You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
Over the next three posts this blog will cover some of the charting changes that have been made in Office 2010, many of which are the direct result of customer feedback.
As part of the Office 2007 release we overhauled charting throughout Office; however an OM for Word and PowerPoint was not provided. In response to your feedback, in Office 2007 SP2 and Office 2010 we’ve exposed a unified/consistent charting OM within Word and PowerPoint, so that you can write solutions against any of the applications that take advantage of the new charting capabilities. The chart is drawn by the same shared Office drawing layer so if you are familiar with the OM in Excel 2007 you can easily create a similar solution in Word or PowerPoint.
Many times companies have a need to create charts in documents or presentations based on client specific data. In many cases these charts have a standard format, size and position which make them a prime candidate for automation. This OM can be used as a part of a solution to automate the generation of these charts which can save many hours of manual labor.
Let’s take a look at an example. Here is an example of how to create a chart in PowerPoint based on data your application has retrieved and apply standard formatting.
Dim myChart As Chart
Dim gChartData As ChartData
Dim gWorkBook As Excel.Workbook
Dim gWorkSheet As Excel.Worksheet
Set myChart = ActivePresentation.Slides(1).Shapes.AddChart.Chart 'create/set chart
Set gChartData = ActivePresentation.Slides(1).Shapes(1).Chart.ChartData 'Set chartdata
Set gWorkBook = gChartData.Workbook 'Set Workbook object reference
Set gWorkSheet = gWorkBook.Worksheets(1) 'Set Worksheet object reference
gWorkSheet.ListObjects("Table1").Resize gWorkSheet.Range("A1:B5") 'Add Data
gWorkSheet.Range("Table1[[#Headers],[Series 1]]").Value = "Sales"
gWorkSheet.Range("a2").Value = "Bikes"
gWorkSheet.Range("a3").Value = "Accessories"
gWorkSheet.Range("a4").Value = "Repairs"
gWorkSheet.Range("a5").Value = "Clothing"
gWorkSheet.Range("b2").Value = "1000"
gWorkSheet.Range("b3").Value = "2500"
gWorkSheet.Range("b4").Value = "4000"
gWorkSheet.Range("b5").Value = "3000"
With myChart 'Apply Style
.ChartStyle = 4
myChart.HasTitle = True 'Add Title
With myChart.ChartTitle 'Format title
.Characters.Font.Size = 18
.Text = "2007 Sales"
With myChart.Axes(xlValue) 'Add axis title
.HasTitle = True
.AxisTitle.Text = "$"
myChart.ApplyDataLabels 'Add data labels
Set gWorkSheet = Nothing
Set gWorkBook = Nothing
Set gChartData = Nothing
Set myChart = Nothing
As you can see a chart is still represented by a ChartObject and in this case is contained by a Shape. It can be contained by either an InlineShape or Shape in Word and a Shape in PowerPoint. From there the ChartObject is generally a mirror of what you would see in Excel. Some key differences are:
The ability to programmatically manipulate charts in Word and PowerPoint also opens the door for a variety of interesting solutions around dynamically changing the appearance of your charts during a presentation or creating an interactive Word document. Here is an example of a solution to add data labels to a chart during a presentation:
Private Sub BtnDataLabels_Click()
Set myChart = ActivePresentation.Slides(1).Shapes(1).Chart 'Set chart object reference
Try it out and let us know what you think!
Thanks Sam for the post. Is there a way where we can specify an array as a source for ChartData?
Shasur - You can pass an array of values directly to the Series.Value or Series.XValues off of the Chart object rather than using the ChartData object.
Wouldn't it be more sensible to write
Set gChartData = myChart.ChartData 'Set chartdata
I like this charting object model better than Microsoft Graph, and the charts look great! I am having trouble getting charting to work calling this model out of Excel's VBA environment, though. Using the example above, it seems like the numbers and formatting don't update from their defaults after running the code in Excel until you manually edit the data and resize the data range. Any suggestions?