How to Add Image/Shape with chart data label in slide

Can we add any shape/image with chart data labels.I need to show one arrow with different colors according to certain values with each data labels in the Untitled.png (7.7 KB)
chart

Hi,

I have observed the requirement shared and like to share that you can add marker symbols or even custom images for chart series data points. Please try using the following sample code on your end to serve the purpose.

    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.LineWithMarkers, 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;

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

Many Thanks,

Mudassir Fayyaz

1 Like

Sir,Thanks.

In my requirement i am unable to edit the marker because i already need the marker(in diamond shape). also i need that triangle shape with each data labelUntitled.png (8.2 KB)

@renjithgovind,

I have observed your requirements in attached image and suggest you to please try using following sample code to serve the purpose.

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

Many Thanks,

Mudassir Fayyaz

The generated, presentation is attached (30.3 KB) for reference.

when i tried to implement this code i am getting 2 issues

  1. Chart.X and label.X is coming as NaN
  2. ActualX is not coming in Label properties

whether the second issue is related to ASPOSE version?

@renjithgovind,

Please accept my apologies for delayed response.

I have used the shared sample code and like to share that I am not getting NaN for chart.X on my end. Also, ActualX value calculated is also right. Please note that ActualX value is w.r.t chart’s top left position. In order to get absolute value of ActualX w.r.t slide, please add Chart.X to ActualX value to get a value w.r.t slide. Lastly, label.X is appearing NanN for a reason. It means that it is default value set by chart. When you will set value by your self, it will appear for it. I hope this is understandable.

Many Thanks,

Mudassir Fayyaz