2012-11-28 29 views
1

我是使用aspose.slides的新手,想知道是否可以創建此鏡頭描述中給出的條形圖。使用Aspose Slide繪製圖形

我試圖更新的圖表的y軸從-100到100,0軸上的x軸和條形圖應該位於正向上升或負向下降。

下圖顯示了代碼定期條形圖是波紋管

// Instantiate PresentationEx class that represents PPTX file 
PresentationEx pres = new PresentationEx("D:\\AsposeChart.pptx"); 

// Access first slide 
SlideEx sld = pres.Slides[0]; 

// Add chart with default data 
ChartEx chart = (ChartEx)sld.Shapes[0]; 

// Setting the index of chart data sheet 
int defaultWorksheetIndex = 0; 

// Getting the chart data worksheet 
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory; 

// Take first chart series 
ChartSeriesEx series = chart.ChartData.Series[0]; 

// Now updating series data 
fact.GetCell(defaultWorksheetIndex, 0, 1, "New_Series1");//modifying series name 
series.Values[0].Value = 90; 
series.Values[1].Value = 123; 
series.Values[2].Value =44; 

// Take Second chart series 
series = chart.ChartData.Series[1]; 

// Now updating series data 
fact.GetCell(defaultWorksheetIndex, 0, 2, "New_Series2");//modifying series name   
series.Values[0].Value = 23; 
series.Values[1].Value = 67; 
series.Values[2].Value = 99; 

// Now, Adding a new series 
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.Type); 

// Take 3rd chart series 
series = chart.ChartData.Series[2]; 

// Now populating series data 
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, 20)); 
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 3, 50)); 
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 3, 30)); 

chart.Type = ChartTypeEx.ClusteredCylinder; 

// Save presentation with chart 
pres.Write(@"D:\AsposeChartMoodified.pptx"); 

回答

0

我觀察您的要求和大家分享,你可以使用下面的代碼片段以服務產生所需的圖表的目的。我已經分享了可以將該系列呈現在負面區域的示例代碼。但是,當呈現負數或小於水平縮放值的值時,會出現一個小問題,它們的填充顏色將被移除。

這是由於缺少Aspose.Slides財產和我已創建了ID SLIDESNET-33821您可以跟蹤這個問題Aspose.Slides產品支持論壇的超過this link狀態)提供的一個問題功能支持。我還分享了突出顯示缺失功能的圖像,並取消了檢查包圍值會填充未填充的系列值。在我看來,如果你正在使用模板圖,那麼這個問題甚至可能不會發生。但是你可以在你的最後驗證這一點。

public static void addBarChart() 
{ 
    PresentationEx pres = new PresentationEx(); 
    ChartEx chart = pres.Slides[0].Shapes.AddChart(ChartTypeEx.ClusteredColumn, 20, 20, 500, 400); 
    //Setting values of Y-axis or Value axis 
    chart.ValueAxis.IsAutomaticMaxValue = false; 
    chart.ValueAxis.IsAutomaticMinValue = false; 
    chart.ValueAxis.CrossType = CrossesTypeEx.Custom; 
    chart.ValueAxis.MinValue = 0; 
    chart.ValueAxis.MaxValue = 400; 
    chart.ValueAxis.CrossAt = 100f; 

    chart.ChartData.Series.Clear(); 
    int defaultWorksheetIndex = 0; 
    //Getting the chart data worksheet 
    ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory; 

    //Adding new series 
    int id=chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type); 
    ChartSeriesEx series = chart.ChartData.Series[id]; 


    //Now populating series data 

    series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 30)); 
    series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 150)); 
    series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 320)); 
    series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 1, 80)); 

    series.Format.Fill.FillType = FillTypeEx.Solid; 
    series.Format.Fill.SolidFillColor.Color = Color.Red; 
    series.IsColorVaried = false; 
    pres.Write("D:\\Aspose Data\\SampleChart.pptx"); 

} 

PS,我的名字是Nayyer和我在的Aspose開發佈道者。