We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Presentation Stacked Charts Issue

I don't want an example project. I just want to know why the second and third columns aren't being presented stacked in the chart.
I should have 5 columns which stack the second and third values.
Instead, I get two columns:
The first stacking the second value of each column.
The second column stacking the last 4 values.
// Creates the two charts that go on the presentation
IPresentationChart chart = slide.Charts.AddChart(150, 100, 300, 125);
// Set data values
chart.ChartData.SetValue(1, 1, date1);
chart.ChartData.SetValue(2, 1, date2);
chart.ChartData.SetValue(3, 1, date3);
chart.ChartData.SetValue(4, 1, date4);
chart.ChartData.SetValue(5, 1, date5);
chart.ChartData.SetValue(1, 2, mains1);
chart.ChartData.SetValue(2, 2, mains2);
chart.ChartData.SetValue(3, 2, mains3);
chart.ChartData.SetValue(4, 2, mains4);
chart.ChartData.SetValue(5, 2, mains5);
chart.ChartData.SetValue(1, 3, variance1);
chart.ChartData.SetValue(2, 3, variance2);
chart.ChartData.SetValue(3, 3, variance3);
chart.ChartData.SetValue(4, 3, variance4);
chart.ChartData.SetValue(5, 3, variance5);
// Chart 1
// Set data range, Title and Category settings
chart.PrimaryCategoryAxis.CategoryType = OfficeCategoryType.Category;
chart.ChartTitle = "";
chart.ChartArea.Fill.Transparency = 0.5;
IOfficeChartSerie serie= chart.Series.Add(date1);
serie.Values = chart.ChartData[1, 2, 1, 3];
serie.SerieType = OfficeChartType.Column_Stacked;
IOfficeChartSerie serie2 = chart.Series.Add(date2);
serie2.Values = chart.ChartData[2, 2, 2, 3];
serie2.SerieType = OfficeChartType.Column_Stacked;
IOfficeChartSerie serie3 = chart.Series.Add(date3);
serie3.Values = chart.ChartData[3, 2, 3, 3];
serie3.SerieType = OfficeChartType.Column_Stacked;
IOfficeChartSerie serie4 = chart.Series.Add(date4);
serie4.Values = chart.ChartData[4, 2, 4, 3];
serie4.SerieType = OfficeChartType.Column_Stacked;
IOfficeChartSerie serie5 = chart.Series.Add(date5);
serie5.Values = chart.ChartData[5, 2, 5, 3];
serie5.SerieType = OfficeChartType.Column_Stacked;
//serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
//serie.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside;
//serie.DataPoints.DefaultDataPoint.DataLabels.Bold = true;
chart.PlotArea.Layout.ManualLayout.Height = 0.9;
chart.PlotArea.Layout.ManualLayout.Width = 1;
chart.PlotArea.Layout.ManualLayout.Left = 0;
chart.PlotArea.Layout.ManualLayout.Top = 0;
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[1, 1, 5, 1];
chart.Legend.IncludeInLayout = false;
chart.HasLegend = false;
Can someone just explain what the issue is? I don't want a whole new project example. I simply want to know the issue.

4 Replies

KK Kumaravel Kulandai Samy Syncfusion Team August 1, 2017 11:48 AM UTC


Hi Doug,
 
The number of columns in the column-stacked chart depends on the number of categories available in the data range. In your code snippet, there are only two category values. So, two columns are displayed in the column - stacked chart.  
Example: serie.Values = chart.ChartData[1, 2, 1, 3]. Here the category values are [ 1, 2 ] and [ 1 , 3 ] 
 
We have also manually created a chart in Microsoft PowerPoint for your scenario (in your code snippet) and attached created PowerPoint presentation in below link. 
We have also modified your code snippet to display the 5 columns in the same chart and highlighted the changes we have made. Please find the code snippet as below. 
IPresentationChart chart = slide.Charts.AddChart(150, 100, 300, 125); 
chart.ChartType = OfficeChartType.Column_Stacked; 
chart.ChartData.SetValue(1, 1, "4355"); 
chart.ChartData.SetValue(2, 1, "4356"); 
chart.ChartData.SetValue(3, 1, "4357"); 
chart.ChartData.SetValue(4, 1, "4358"); 
chart.ChartData.SetValue(5, 1, "4359"); 
chart.ChartData.SetValue(1, 2, "6"); 
chart.ChartData.SetValue(2, 2, "7"); 
chart.ChartData.SetValue(3, 2, "8"); 
chart.ChartData.SetValue(4, 2, "9"); 
chart.ChartData.SetValue(5, 2, "10"); 
chart.ChartData.SetValue(1, 3, "11"); 
chart.ChartData.SetValue(2, 3, "12"); 
chart.ChartData.SetValue(3, 3, "13"); 
chart.ChartData.SetValue(4, 3, "14"); 
chart.ChartData.SetValue(5, 3, "15"); 
// Set data range, Title and category settings 
chart.PrimaryCategoryAxis.CategoryType = OfficeCategoryType.Category; 
chart.ChartTitle = ""; 
chart.ChartArea.Fill.Transparency = 0.5; 
IOfficeChartSerie serie = chart.Series.Add("date1"); 
//selecting data from first row second column to fifth row second column 
//ChartData[startRow,startColumn,endRow,endColumn] 
serie.Values = chart.ChartData[1, 2, 5, 2]; 
serie.SerieType = OfficeChartType.Column_Stacked; 
IOfficeChartSerie serie2 = chart.Series.Add("date2"); 
//selection data from first row third column to fifth row third column 
serie2.Values = chart.ChartData[1, 3, 5, 3]; 
serie2.SerieType = OfficeChartType.Column_Stacked; 
chart.PlotArea.Layout.ManualLayout.Height = 0.9; 
chart.PlotArea.Layout.ManualLayout.Width = 1; 
chart.PlotArea.Layout.ManualLayout.Left = 0; 
chart.PlotArea.Layout.ManualLayout.Top = 0; 
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[1, 1, 5, 1]; 
chart.Legend.IncludeInLayout = true; 
chart.HasLegend = false; 
Output Document for the above modified code snippet: 
Please let us know if you need further assistance on this, 
Regards, 
Kumaravel 



DO Doug August 1, 2017 01:54 PM UTC

That worked perfect. The other question is how to get the columns to show their value on the chart. I've got that to work before with single columns, but with the stacked it seems to break the presentation.


I'm using the following code.


                serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;

                serie.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside;

                serie.DataPoints.DefaultDataPoint.DataLabels.NumberFormat = "0";

                serie.DataPoints.DefaultDataPoint.DataLabels.Bold = true;



DO Doug August 1, 2017 03:30 PM UTC

I figured it out. You can't use "outside" with  a Stacked Chart. I switched it so that the bottom value uses "Center" and the top value uses "Inside" and it got close to what I was looking for.



KK Kumaravel Kulandai Samy Syncfusion Team August 2, 2017 10:13 AM UTC

Hi Doug, 
We are happy to know that you have achieved your requirement at your end. 
Regards, 
Kumaravel.K 


Loader.
Up arrow icon