Question

I am trying to implement a StackedColumn type chart in my project, however I find to understand how to properly assign the different Series.

This is demo purpose code:

for (int i = 1; i <= 3; i++)
{
    for (int a = 0; a < 5; a++)
    {
        string item = "boo" + i.ToString() + a.ToString();

        chart1.Series.Add(item);
        chart1.Series[item].ChartType = SeriesChartType.StackedColumn;
        chart1.Series[item].Points.AddXY(i, 100.0);
    }
}

However, this produces flying 3 stacked columns instead of 3 equal stacked columns:

flying stacked column

However, if I remove the SeriesChartType.StackedColumn (and use the default) it works just fine and they go to the ground. How should I make them go to the bottom using StackedColumn?

Was it helpful?

Solution

You are currently creating a chart with 15 series, each series has only 1 data point. Is this what you are trying to achieve? For example if you wanted to have 3 series, each with 5 data points you should do something like this:

for (int i = 1; i <= 3; i++)
{
    // add a series to the chart
    string item = "boo" + i.ToString();
    chart1.Series.Add(item);
    chart1.Series[item].ChartType = SeriesChartType.StackedColumn;
    for (int a = 1; a <= 5; a++)
    {
        // add 5 points to the current series 
        chart1.Series[item].Points.AddXY(a, 100.0);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top