堆叠图表格式Syncfusion

时间:2017-07-31 18:53:09

标签: c# charts syncfusion

我应该有5列堆叠第二和第三个值。

相反,我得到两列:

第一个堆叠每列的第二个值。

第二列堆叠最后4个值。

我不确定我做错了什么。在过去的一周里,我一直在与Syncfusion进行斗争,试图获得我想到的,为客户构建的相当基本的幻灯片。然而,到目前为止,这一直是一场噩梦。

// 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;

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; 

1 个答案:

答案 0 :(得分:0)

列堆积图表中的列数取决于数据范围中可用的类别数。在您的代码段中,只有两个类别值。因此,列中显示两列 - 堆积图表。

Example: serie.Values = chart.ChartData[1, 2, 1, 3]; 

这里的类别值是[1,2]和[1,3]。

我们还在Microsoft PowerPoint中为您的方案手动创建了一个图表(在您的代码片段中),并在下面的链接中附加了创建的PowerPoint演示文稿。 http://www.syncfusion.com/downloads/support/directtrac/general/pp/Chart1370190114.pptx

我们还修改了您的代码段以显示5列。请在下面找到代码段。

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]; //Modified the data range to have 5 columns
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]; //Modified the data range to have 5 columns
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;

以上修改过的代码段的输出文档

http://www.syncfusion.com/downloads/support/directtrac/general/pp/Output-549061229.pptx

如果您需要进一步的帮助,请告诉我们,

注意:我在Syncfusion Software Private Limited工作