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

Chart series data not displaying correctly when .AutoScale = false

2 Answers 78 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris Ward
Top achievements
Rank 1
Chris Ward asked on 07 Feb 2011, 09:55 PM
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:
//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

2 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 10 Feb 2011, 01:39 PM
Hi Chris Ward,

The easiest way to configure the chart to display custom labels along the X axis is to set the PlotArea.DataLabelsColumn. This works just like ChartSeries.DataYColumn i.e. this is the name of the column holding the text that you need displayed as X axis item labels. You will need to remove the X axis related code shown in your code snippet.

Kind regards,
Ves
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Chris Ward
Top achievements
Rank 1
answered on 10 Feb 2011, 10:13 PM
Thank you.  I was able to make this work using your suggestion.  At first I couldn't get it to work because the column I was trying to bind to the labels was a SmallDateTime field in my SQL server.  In my SQL statement I converted it to a string and then I could bind as expected.

Thanks,

Chris
Tags
General Discussions
Asked by
Chris Ward
Top achievements
Rank 1
Answers by
Ves
Telerik team
Chris Ward
Top achievements
Rank 1
Share this question
or