I have a line chart with a numeric data series (1,5) (2,1.5)(3,1.5)(4,1.5) as the data source.
The chart is rendered fine but I want to see 0 in x axis and y axis. I added a numeric datapoint(0,"0")
so it shows up on the chart. But I do not want this datapoint to be included in the line. Is there anyway to
have 0,0 or zero aligned axes but chart plots only for the data values. Any help is appreciated.
Try setting chart.Data.ZeroAligned = true
No, that doesnt work. I am assuming it will work only with datatable/dataset as data source?
Not necessarily. This won't work if you have a composite chart, but if it's a regular line chart, it should work regardless of the datasource. However, I'm not sure which chart type you're using, because a LineChart cannot be bound to a series that has 2 numeric values as both X and Y. Only a ScatterChart can do that. It might help if you posted a more complete code snippet showing the chart type and the series type. If you're using a composite chart, you can either set a range on your axis to include 0, or you can create an additional series that matches the number of points in the other series with all empty values.
I am using a line chart and not a composite chart. The Line chart is taking a numeric data series.
Following is the code:
NumericSeries numLineChart = new NumericSeries();//data source for the line chart
//Add a datapoint for (0,0) numLineChart.Points.Add(new NumericDataPoint(0,"0", true)); int i = 1;
foreach(DataRow dr in childRows) { numLineChart.Points.Add(new NumericDataPoint((double)dr["Value"], i.ToString(), false)); i++; }
//Display the line chart UltraChart ucLineChart = (UltraChart)scc.FindControl("UltraChart_Line"); ucLineChart.LineChart.ChartComponent.Series.Add(numLineChart);
Setting ZeroAligned to true will only affect numeric axes. Since your X axis is string based, ZeroAligned will have no effect on it. However, you can still use one empty point as long as you set NullHandling to DontPlot. Here's an example:protected void Page_Load(object sender, EventArgs e){ NumericSeries numLineChart = new NumericSeries(); numLineChart.Points.Add(new NumericDataPoint(0, "0", true));
for(int i=1; i<5;i++) { numLineChart.Points.Add(new NumericDataPoint((double)i, i.ToString(), false)); }
//Display the line chart UltraChart ucLineChart = (UltraChart)this.FindControl("UltraChart_Line"); ucLineChart.Series.Add(numLineChart); //ucLineChart.Data.ZeroAligned = true; ucLineChart.LineChart.NullHandling = NullHandling.DontPlot;}
That worked! Thanks...I changed the chart type to spline chart and then it plots the point again.
Any reason? Clients want a smooth curve.....
I tried that before and did not work. But I figured out why. I was adding the series to the linechart setting null handling of spline chart. Anyways now it is working as needed. Thank you for your help.
NullHandling is chart type specific. When you use properties under chart.LineChart it will only affect line charts. Use chart.SplineChart.NullHandling instead for spline charts.