-1

I create a Column chart using Kendo ui dataviz. In my program, i am going to bind the local Javascript Array variable data to chart datasource. The JSON data was spilted like "3""9""6" for "396". I dont know why it happened. My Source code is given blow. Please check it and Please give the solution.

Source:

/**************Variable Declaration**********************************/
var eligibilityData = new Array();
eligibilityData = {
    mem_status: {
        a: 396, b: "56", c: "1125", d: "8423"
    }
};

/**************Create Chart**********************************/
function createBarChart(eligibilityData) {
    /****** Issue: A value is 396 but it spilted into "3","9","6"************/
    $("#Chart1").kendoChart({
        theme         : $(document).data("kendoSkin") || "default",
        dataSource    : {
            data: JSON.stringify(eligibilityData.mem_status.a),
        },
        seriesDefaults: { type: "column", },
        series        : [
            { field: "a", name : "A" }
        ],
        tooltip       : { visible: true, },
    });
}
kmp
  • 10,535
  • 11
  • 75
  • 125

2 Answers2

1

Local data should be passed as an array. No need to call JSON.stringify

data: [eligibilityData.mem_status]

See: http://docs.kendoui.com/api/framework/datasource#configuration-data-Array

Tsvetomir Tsonev
  • 105,726
  • 5
  • 27
  • 34
0

JSON.stringify does not do what you expect. What you sentence really does is:

  1. It gets the number 396 and converts it to a string.
  2. Converts a string into an array of one character per element.

Not sure about the way you define the DataSource (why you want a DataSource with only one element) but if that is really what you want, you might try:

dataSource    : {
    data: [eligibilityData.mem_status.a]
},

or

dataSource    : {
    data: [eligibilityData.mem_status]
},
OnaBai
  • 40,767
  • 6
  • 96
  • 125