Hello Telerik,
I am creating a chart from a SQL datasource. I have two series that are bound to columns on the datasource. If I preview the chart, it looks good and the chart matches the data. My next step is to display my own custom X-Axis labels. I do this by setting PlotArea.XAxis.AutoScale = false and create the items manually. However when I do this and preview the chart, the chart does not look correct (the line does not match the data from the database).
This forum post seems to be related: http://www.telerik.com/community/forums/aspnet/chart/trouble-with-custom-xaxis-labels.aspx
It suggests that I do not set the xvalue inside my chart series. However, I am adding the series by binding to a datasource, so I do not see how to make this work in my case.
Here is my code:
Am I doing this totally wrong, or is there a work around?
Thanks, Chris
I am creating a chart from a SQL datasource. I have two series that are bound to columns on the datasource. If I preview the chart, it looks good and the chart matches the data. My next step is to display my own custom X-Axis labels. I do this by setting PlotArea.XAxis.AutoScale = false and create the items manually. However when I do this and preview the chart, the chart does not look correct (the line does not match the data from the database).
This forum post seems to be related: http://www.telerik.com/community/forums/aspnet/chart/trouble-with-custom-xaxis-labels.aspx
It suggests that I do not set the xvalue inside my chart series. However, I am adding the series by binding to a datasource, so I do not see how to make this work in my case.
Here is my code:
//set the datasource chart1.DataSource = this.sqlDataSource1; //COMMENT OUT THIS SECTION AND THE CHART LOOKS GOOD //add new xaxis series items chart1.PlotArea.XAxis.AutoScale = false; chart1.PlotArea.XAxis.AddRange(1, 7, 1); chart1.PlotArea.XAxis[0].TextBlock.Text = "12/1/10"; chart1.PlotArea.XAxis[1].TextBlock.Text = "12/5/10"; chart1.PlotArea.XAxis[2].TextBlock.Text = "12/10/10"; chart1.PlotArea.XAxis[3].TextBlock.Text = "12/15/10"; chart1.PlotArea.XAxis[4].TextBlock.Text = "12/20/10"; chart1.PlotArea.XAxis[5].TextBlock.Text = "12/25/10"; chart1.PlotArea.XAxis[6].TextBlock.Text = "12/30/10"; //add the series 1 ChartSeries seriesAvg = new ChartSeries(); seriesAvg.DataYColumn = "Average"; seriesAvg.Type = ChartSeriesType.Area; seriesAvg.DefaultLabelValue = ""; chart1.Series.Add(seriesAvg); //add the series 2 ChartSeries seriesMax = new ChartSeries(); seriesMax.DataYColumn = "Max"; seriesMax.Type = ChartSeriesType.Line; seriesMax.DefaultLabelValue = ""; chart1.Series.Add(seriesMax);Am I doing this totally wrong, or is there a work around?
Thanks, Chris