Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Stacked column chart is not working in asp.net chart


i am looking for the below output

1. For Actual and unavaialbel_Actual columns the charttype should be stakced column
2. For Budget column the chart type should be column

What I have tried:

foreach (DataRow r in initialDataSource.Rows)
           {
               series.Points.AddXY("Actual", r["Actual"].ToString());
               series.Points.AddXY("unavailable_actual", r["unavailable_actual"].ToString());
               series.Points.AddXY("budget", r["budget"].ToString());

               series.Points[0].Color = System.Drawing.Color.Red;
               series.Points[1].Color = System.Drawing.Color.Green;
               series.Points[2].Color = System.Drawing.Color.Blue;

               Chart1.Series.Add(series);
               series.ChartType = SeriesChartType.StackedColumn;
           }
Posted
Updated 28-May-20 21:36pm
v2
Comments
manasa anandi 29-May-20 3:24am    
Hello, I want to display actual and unavailable actual in stacked column and budget in column chartype

1 solution

It all depends on what you mean by 'not working'.
Maybe you just need to treat Y values as double, instead of string?
C#
foreach (DataRow r in initialDataSource.Rows)
{
   series.Points.AddXY("Actual", double.Parse(r["Actual"].ToString()));
   series.Points.AddXY("unavailable_actual", double.Parse(r["unavailable_actual"].ToString()));
   series.Points.AddXY("budget", double.Parse(r["budget"].ToString()));

   // ...
}
 
Share this answer
 
Comments
Richard Deeming 28-May-20 15:39pm    
The X value needs to be a double as well; "Actual", "unavailable_actual", and "budget" are not valid X values. :)

DataPointCollection.AddXY Method (System.Web.UI.DataVisualization.Charting) | Microsoft Docs[^]
phil.o 28-May-20 15:50pm    
That puzzled me too, what I proposed is just a long, long shot. Under this form, I guess the AddXY(Object, Object[]) overload will be used.
The meaning of 'not working' should really be detailed.
Maciej Los 29-May-20 4:31am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900