Hello,
I am trying to create a spline area chart with the ASP.NET charting controls. Unfortunately, I have been unable to make it do everything I want to do. I want the horizontal axis of the chart to always show the lower and upper bounds of the data set at an interval of 1. The lower bounds will always be 1 and the upper bounds will always be 10. However, I can only seem to do this if the number of entries in my y-series values has 10 entries (1 to correspond with each point in the interval). But there are some cases where my y-series will have less than 10 values, like 5 for instance. How do I show all 10 points on the x-axis, even when my y-series has less than 10 values? Here is what I have tried thus far.
// Create the chart
Chart chart = new Chart();
chart.Width = new Unit(750, UnitType.Pixel);
chart.Height = new Unit(500, UnitType.Pixel);
// Add a chart area to the chart
ChartArea chartArea = new ChartArea("chartArea1");
chart.ChartAreas.Add(chartArea);
// Setup the chart series
Series series = new Series("series1");
series.ChartType = SeriesChartType.SplineArea;
chart.Series.Add(series);
// Add the X-Axis
Axis axis = new Axis(chartArea, AxisName.X);
chart.ChartAreas["chartArea1"].AxisX.Interval = 1.0;
chart.ChartAreas["chartArea1"].AxisX.Minimum = 1;
chart.ChartAreas["chartArea1"].AxisX.Maximum = 10;
// Add the Y-Axis
Axis axis = new Axis(chartArea, AxisName.Y);
chart.ChartAreas["chartArea1"].AxisY.Crossing = -5; // Note: the crossing is necessary
// Create the data series
string[] xValues = new string[10];
int[] yValues = new int[10];
// Setup the x-and-y data points
for (int i = 1; i <= 10; i++)
{
xValues[i - 1] = i.ToString();
yValues[i - 1] = tempValues[i - 1]; // Moving values from a generated data set
}
// Bind the data to the chart now that it is constructed
chart.Series["series1"].Points.DataBindXY(xValues, yValues);
If you run this code you will notice that the graph tries to fade out. In reality, I just want to cut it off where the yValues end.
Thank you for looking at this.