2017-06-22 110 views

回答

2

我觀察到您的要求和希望共享MS PowerPoint支持LineWithMarker圖表,可以爲不同的一系列數據點顯示(在圖像的形式)不同的預定義的或定製的標記符號。請嘗試使用下面的示例代碼使用Aspose.Slides和MSO圖表可能的選擇。

public static void TestScatter() 
{ 
    var location = System.Reflection.Assembly.GetExecutingAssembly().Location; 

    //Open a presentation 
    Presentation pres = new Presentation(); 
    IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.StackedLineWithMarkers, 10, 10, 400, 400); 
    //populating cycle 
    var serie = chart.ChartData.Series[0]; 
    var wbk = chart.ChartData.ChartDataWorkbook; 
    chart.ChartData.Series.RemoveAt(1); 
    chart.ChartData.Series.RemoveAt(1); 

    serie.Marker.Format.Fill.FillType = FillType.Picture; 
    serie.Marker.Size = 20; 

    // Set the picture 
    System.Drawing.Image img = (System.Drawing.Image)new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg"); 
    IPPImage imgx = pres.Images.AddImage(img); 
    serie.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx; 

    //For individual data point 
    serie.DataPoints[0].Marker.Format.Fill.FillType = FillType.Solid; 
    serie.DataPoints[0].Marker.Format.Fill.SolidFillColor.Color = Color.Red; 
    serie.DataPoints[0].Marker.Size = 20; 
    serie.DataPoints[0].Marker.Symbol = MarkerStyleType.Triangle; 

    serie.DataPoints[0].Label.DataLabelFormat.ShowValue = true; 
    serie.DataPoints[1].Label.DataLabelFormat.ShowValue = true; 
    serie.DataPoints[2].Label.DataLabelFormat.ShowValue = true; 
    serie.DataPoints[3].Label.DataLabelFormat.ShowValue = true; 

    pres.Save(Path.Combine(Path.GetDirectoryName(location), "Result2.pptx"), SaveFormat.Pptx); 

} 

我的工作是支持開發者/佈道者的Aspose。

非常感謝,

+0

感謝您的支持,但我需要與數據的標籤,符號不marker.in上圖中我發現只有我定位在marker.If的權利我去與數據的標籤,符號標記可以使設計完全像這樣? – user3501613

+0

我用標記取代了圖像(請檢查上面的圖像)。根據上述解決方案,如果我改變標記和放置圖像的位置將是錯誤的。在我將如何改變標記的位置? – user3501613

+0

我需要兩個標記(鑽石)和數據標籤,所以如果我們編輯標記,那麼所需的設計將出錯 – user3501613

1

我進一步觀察你的要求,並已觀察到,你也張貼在Aspose.Slides official support forum有類似的需求也是如此。請嘗試使用以下示例代碼來達到目的。

public static void TestLineChart() 
{ 
var location = System.Reflection.Assembly.GetExecutingAssembly().Location; 

//Open a presentation 
Presentation pres = new Presentation(); 
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.StackedLineWithMarkers, 10, 10, 400, 400); 
//populating cycle 
var serie = chart.ChartData.Series[0]; 
var wbk = chart.ChartData.ChartDataWorkbook; 
chart.ChartData.Series.RemoveAt(1); 
chart.ChartData.Series.RemoveAt(1); 

serie.Marker.Format.Fill.FillType = FillType.Picture; 
serie.Marker.Size = 20; 


serie.Marker.Symbol = MarkerStyleType.Diamond; 
serie.Marker.Format.Fill.FillType = FillType.Solid; 
serie.Marker.Format.Fill.SolidFillColor.Color=Color.Orange; 
serie.Marker.Format.Line.FillFormat.FillType = FillType.Solid; 
serie.Marker.Format.Line.FillFormat.SolidFillColor.Color=Color.Red; 
serie.Marker.Format.Line.Width=1.0F; 

serie.Format.Line.Width = 3.0f; 
serie.Format.Line.FillFormat.FillType=FillType.Solid; 
serie.Format.Line.FillFormat.SolidFillColor.Color = Color.FromArgb(209,225,91) ; 

for(int i=0;i<serie.DataPoints.Count;i++) 
{ 
serie.DataPoints[i].Label.DataLabelFormat.ShowValue = true; 
    IDataLabel label=serie.Labels[i]; 
    chart.ValidateChartLayout(); 
    IAutoShape ashp=chart.UserShapes.Shapes.AddAutoShape(ShapeType.Triangle,chart.X + label.ActualX + 5, chart.Y + label.ActualY + 5, 20,20); 
    ashp.FillFormat.FillType = FillType.Solid; 

    ashp.LineFormat.FillFormat.FillType = FillType.NoFill; 
    if (i % 2 == 0)//even data points 
    { 
     ashp.FillFormat.SolidFillColor.Color = Color.Green; 
    } 
    else 
    { 
     ashp.Rotation = 180; 
     ashp.FillFormat.SolidFillColor.Color = Color.Red; 
    } 
} 

pres.Save(Path.Combine(Path.GetDirectoryName(location), "Result2.pptx"), Aspose.Slides.Export.SaveFormat.Pptx); 

} 

我在Aspose擔任Support developer/Evangelist。

非常感謝,

+0

當我試圖實現此代碼我得到2個問題 1. Chart.X和label.X即將到來NaN(而不是ActualX我使用了X) 2. ActualX沒有出現在Label屬性中 第二個問題是否與ASPOSE版本有關? – user3501613