Take the 2-minute tour ×

I have an excel sheet with 3 columns. Column B and C are my data and column A contains the labels for each point.

I had to use this to get my chart right

series1Point.XValues = xlWorkSheetDimfract.get_Range("B1:B" + (ip - 1));
series1Point.Values = xlWorkSheetDimfract.get_Range("C1:C" + (ip - 1));

But the labels of column A are not showing even with:


How do I add the labels to each point on my chart based on what is written in Column A and get that chart into a jpeg afterwards?


Excels.SeriesCollection seriesCollectionPoint = chartPageDimfract.SeriesCollection();

Excels.Series series1Point = seriesCollectionPoint.NewSeries();
 series1Point.XValues = xlWorkSheetDimfract.get_Range("A1:B" + (ip - 1));

        chartPageDimfract.ChartType = Excels.XlChartType.xlXYScatter;// xlLineMarkers;

        series1Point.MarkerStyle = Excels.XlMarkerStyle.xlMarkerStyleDot;
        series1Point.MarkerSize = 4;

        chartPageDimfract.Export(xlsfic + "temp/dimmensionFractale.jpg", "JPG", misValue);

        xlWorkBookDimfract.SaveAs(xlsfic + "temp/excel_chart_dimmensionFractale.xls",    Excels.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excels.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
   xlWorkBookDimfract.Close(true, misValue, misValue);

'ip' is an integer I used after filling my excel sheet. Its the index of the last item.

share|improve this question
Have you seen this link –  Siddharth Rout Apr 18 '13 at 22:23
Yes I did.... but it didn't work for me... –  Olivier Corimbelly Apr 18 '13 at 22:27
.SetSourceData does not give the correct graph.. –  Olivier Corimbelly Apr 18 '13 at 22:36
Here is one link where I have mentioned how to add data labels –  Siddharth Rout Apr 18 '13 at 22:40
Scatterplot does not natively support this sort of labeling. I have a macro that I use routinely to apply labels like this to scatterplot charts. If it will help you, I will post it momentarily. –  David Zemens Apr 18 '13 at 22:59
add comment

1 Answer

As I mentioned in the comments, the chart type XY Scatterplot does not natively support the sort of labeling that you are trying to do. It allows for you to label with either the X, the Y, or both the X and Y values, but not with some categorical values.

Create an array that contains the labels you want to apply. The array should be in the same order and contain as many labels as the series has points.

Then, this is the method that I use in VBA:

 Sub AddXYScatterLabels()

 Dim ptLabels as Variant     '<~~ this is the array that I will populate with the labels to use from Column A.

 Dim i as Long: i=1
 Dim srs as Series           '<~~ This is the series that you will assign the labels to.'
 Dim pt as Point             '<~~ use this to iterate over srs.Points collection.'
 ptLabels = Range("A1:A10")  '<~~ Modify as needed for your Range object.'

 Set srs = ActiveSheet.ChartObjects(1).SeriesCollection(1) 

 For each pt in srs.Points
     pt.DataLabel.Text = ptLabels(i,1)
     i = i+1

 End Sub

Then, you should be able to use the Chart.Export method to create a JPG of the chart.

ActiveChart.Export "c:\chart.jpg"
share|improve this answer
Thnk you man! helped! –  Olivier Corimbelly Apr 18 '13 at 23:24
+ 1 Good work :) –  Siddharth Rout Apr 18 '13 at 23:35
add comment

Your Answer


