This is a migrated thread and some comments may be shown as answers.

[Solved] Json DataSource Connection Issue with RadChart

3 Answers 119 Views
Chart for HTML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Varun
Top achievements
Rank 1
Varun asked on 17 May 2013, 09:10 PM
Hi,

I have some data in my Json file and I am trying to populate the data in the chart. You can see the code in ChartDatasourceconnection Image.

When I am writing the command
dataSource.Read().then(function() {
});

ideally, it should read the json file and then when I assign the same datasource to chart, it should populate the resutls. But when I debug it, nothing is read from through the dataSource.Read() command.

Please let me know were I am going wrong.

3 Answers, 1 is accepted

Sort by
0
Martin Yankov
Telerik team
answered on 18 May 2013, 03:43 PM
Hi Varun,

I have looked trough your code and found two problems:

1)  When you initialize the DataSource object, you use "dataSource" as a property and place the "transport" and "schema" properties in it. This is not a valid constructor for the DataSource control. You should place "transport" and "schema" directly in the constructor instead.

2) When setting the "url" to the target resource, you should use a normal slash for setting the path instead of a backslash.

var chart = document.getElementById("myChart").winControl;
chart.title.text = "Automation Statics";
 
var dataSource = new Telerik.Data.DataSource({
    transport: {
        read: {
            url: "pages/color.json",
            dataType: "json"
        }
    },
    schema: {
        data: "colorsArray",
        model: {
            fields: {
                hexValue: { type: "number" }
            }
        }
    }
});
 
chart.dataSource = dataSource;
 
var series = new Telerik.UI.Chart.ColumnSeries();
series.field = "hexValue";
chart.series.push(series);
chart.categoryAxis.field = "colorName";
 
chart.refresh();

You can also find attached a working project with your problem for reference. 

There are two more things, that I can point out:

 - When reading from a resource, where the numeric values you want to populate the chart with, are strings, it is best to provide a model in the DataSource to specify that the field is a number.

 - It is not necessary to call the read() method when you want to just bind the DataSource to a control. This is because the control calls it automatically when you assign a resource to it's dataSource property.

All the best,
Martin Yankov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Zeeshan
Top achievements
Rank 1
answered on 11 Jul 2013, 01:57 PM
There is no connection with the datasource
0
Zeeshan
Top achievements
Rank 1
answered on 11 Jul 2013, 01:58 PM
There is no connection with the datasource and creating issue with radchart
Tags
Chart for HTML
Asked by
Varun
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Zeeshan
Top achievements
Rank 1
Share this question
or