Excel Datalabels

Can anyone help me with how to use “Office.xlDataLabelsShowLabelAndPercent” when formatting a chart in Excel within Realbasic please

I have gotten as far as “Excel.ActiveChart.SeriesCollection(1).ApplyDataLabels” but wish to apply the above to the PIE chart but I cannot work out the correct syntax to use it.

Also why is talking to Exel windows platform specific as Office(incl Excel) is available on a MAC and the wiki sort of teases you into thinking there is an excelapplication for a MAC but gets you back to windows page. Just curious to know.


Hi Nick,

Here is an example which uses the Office.xlDataLabelsShowLabelAndPercent on a Pie Chart.

Here is the code to create the chart on a Windows 8 OS with Xojo Windows IDE 2013 R1:

[code] Dim Excel as new ExcelApplication
Dim Chrt as ExcelChart
excel.visible = true //Show Excel
excel.workbooks.add // Add a workbook for our data

//Add data to excel workbook
excel.range(“A1”).value = “Ford”
excel.range(“A2”).value = “GMC”
excel.range(“A3”).value = “Dodge”
excel.range(“A4”).value = “Toyota”
excel.range(“A5”).value = “Honda”
excel.range(“A6”).value = “John Deere”

excel.range(“B1”).value = “100”
excel.range(“B2”).value = “300”
excel.range(“B3”).value = “150”
excel.range(“B4”).value = “600”
excel.range(“B5”).value = “400”
excel.range(“B6”).value = “1040”

excel.Charts.add //add the chart
excel.charts.Select_ //select the chart

excel.ActiveChart.SetSourceData Excel.Sheets(“Sheet1”).Range(“A1:B6”) // Select the data Range
excel.ActiveChart.ChartType = office.xl3DPieExploded //Choose the Chart Type
excel.activechart.PlotBy = office.xlvalue //Plot the data by columns

excel.ActiveChart.HasTitle = True
excel.ActiveChart.ChartTitle.Characters.Text = “‘Likes’ Survey”
excel.ActiveChart.ApplyDataLabels(Office.xlDataLabelsShowLabelAndPercent, False, False, True)
excel.ActiveChart.SeriesCollection(1).Datalabels.NumberFormat = “0%”

Exception err //Report errors
MsgBox err.message[/code]

LOL, I am not responsible for the results of this survey, as there must have been a few country folk involved :slight_smile:



Many many thanks for this Eugene. Your example, not only giving me the labels&percentages, has answered several other questions I was asking myself as well. I really must get round to buying your book!

Thanks again


Hello Nick,

Your welcome.

This example (4-11) has been added to the next version of the book Wish I Knew How To… Program Excel 2010 with Xojo in Windows (version 2.1) that I am targeting for an August release date. I Wish I Knew How To… Series Link

Enjoy :slight_smile: