binding chart data to a dataset

I'm new to syncfusion and am trying to bind data from a dataset to a syncfusion chart, the code I'm using is as follows:

ChartSeries series1 = new ChartSeries(" Unit Sales ");
series1.Type = ChartSeriesType.Scatter;

ChartDataBindModel dataSeriesModel = new ChartDataBindModel(unitSalesKPI);

series1.SeriesModel = dataSeriesModel;
ChartWebControl1.Series.Add(series1);

The data that resides in the dataset looks like this:
full_date value_wtd
2009-03-30 00:00:00.000 8.00
2009-03-31 00:00:00.000 28.00
2009-04-01 00:00:00.000 47.00
2009-04-02 00:00:00.000 55.00
2009-04-03 00:00:00.000 100.00

I could only find 1 example anywhere in the documentation, please advise... thank you!


2 Replies

AD Administrator Syncfusion Team July 15, 2009 05:57 PM UTC

I've actually made some progress on this but cannot get the chart to recognize the data...

The DataSet has the following:

day_of_week_short_desc value_wtd
Mon 8.00
Tue 28.00
Wed 47.00
Thu 55.00
Fri 100.00

day_of_week_short_desc is the x-axis and value_wtd is the y-axis

I'm trying to create a chart. The chart seems to realize that the data is there but the x/y axes and plotting is not correct.

Here is the code that I am using:

ChartSeries series1 = new ChartSeries(" Unit Sales ");
series1.Type = ChartSeriesType.Scatter;
ChartDataBindModel dataSeriesModel = new ChartDataBindModel(unitSalesKPI, "unit_sales_kpi");
series1.SeriesModel = dataSeriesModel;
ChartWebControl1.Series.Add(series1);

ChartDataBindAxisLabelModel dataLabelsModel = new ChartDataBindAxisLabelModel(unitSalesKPI, "unit_sales_kpi");
dataLabelsModel.LabelName = "Name"; //"day_of_week_short_desc";
ChartWebControl1.PrimaryXAxis.LabelsImpl = dataLabelsModel;

this.ChartWebControl1.Series[0].ScatterConnectType = ScatterConnectType.Line;

I have attached a picture of the chart that is being produced.

Please advise,

Thank you







chart_6a5edd2d.bmp


VV Venkata Vijayaraj B Syncfusion Team July 16, 2009 07:03 AM UTC

Hi Bill,

Thank you for using Essential Chart.

//To plot dataset's table values, bind the x column and y column of the table to chartDataBindModel's XName, YNames
properties.

ChartDataBindModel model = new ChartDataBindModel(dataSet, "Demographics");
model.XName = "ID";
model.YNames = new string[] { "Population" };
series.SeriesModel = model;


If 'XName' property of ChartDataBindModel is not assigned then Chart will taken the X Axis values from Zero [0, 1,
2, ...] automatically and plot the yvalues.

//To set the axis labels

//Set the below property to display the custom labels.
this.ChartWebControl1.PrimaryXAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode;

private ChartDataBindAxisLabelModel xAxisLabelModel = null;
this.xAxisLabelModel = new ChartDataBindAxisLabelModel(dataSet, "Demographics");
this.xAxisLabelModel.LabelName = "City";

this.ChartWebControl1.PrimaryXAxis.LabelsImpl = this.xAxisLabelModel;

Sample Link:

http://files.syncfusion.com/support/Chart.Web/v7.3.0.20/I57989/main.htm


Please let me know if you need any other detail.

Regards,
Venkat.

Loader.
Up arrow icon