2017-07-31 75 views
1

我應該有5列堆積第二和第三個值。堆棧圖格式Syncfusion

相反,我得到兩列:

第一疊合第二每一列的值。

第二列堆疊最後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; 

回答

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軟件工作私人有限公司