Creating Charts in Excel using Automations

rkaufmann
Member Posts: 71
Hi,
I create an Excel-Sheet with Navision using Automation-Variables to control Excel.
Creating a Excel-Sheet and fill it with data is not a problem, but now I want to create a chart based on the data in the Excel-Sheet.
I use the following Globals of type Automation:
xlApp: 'Microsoft Excel 11.0 Object Library'.Application
xlWorkbook 'Microsoft Excel 11.0 Object Library'.Workbook
xlWorksheet: 'Microsoft Excel 11.0 Object Library'.Worksheet
xlRange: 'Microsoft Excel 11.0 Object Library'.Range
xlChart: 'Microsoft Excel 11.0 Object Library'.Chart
xlChartObject: 'Microsoft Excel 11.0 Object Library'.ChartObject
xlChartObjects: 'Microsoft Excel 11.0 Object Library'.ChartObjects
xlSeriesCollection: 'Microsoft Excel 11.0 Object Library'.SeriesCollection
xlSeries: 'Microsoft Excel 11.0 Object Library'.Series
Now I use the folloing C/AL-Code to create the chart:
xlChartObjects := xlworksheet.ChartObjects; //Create an instance for automation
xlChartObject := xlChartObjects.Add(xlApp.CentimetersToPoints(15),xlApp.CentimetersToPoints(5),
xlApp.CentimetersToPoints(8),xlApp.CentimetersToPoints(9)); //Create a new chart an place it on the sheet
xlChart := xlChartObject.Chart; // Create an instance for the autoamation
xlChart.ChartType(54); // setting the chart type (54 = 3D Column Clustered)
xlSeriesCollection := xlChart.SeriesCollection; // create an instance for the automation
xlSeries := xlSeriesCollection.NewSeries; // create a new Dataseriens in the chart
Till here everything works fine.
But now I want to "tell" the new Dataseries from where to get the Data, and that's my problem. It does not work.
When recording a Macro in Excel the VBA-Code looks linke this:
ActiveChart.SeriesCollection(1).Values = "=(Tabelle1!R15C3,Tabelle1!R22C3,Tabelle1!R29C3,Tabelle1!R36C3)"
If i use C/AL Code like:
xlSeries.Values := 'C5:C29';
xlSeries.Values := '=C5:C29';
xlSeries.Values := 'Sheet1!C5:Sheet1!C29';
xlSeries.Values := '=Sheet1!C5:Sheet1!C29';
it does not work.
Using
xlSeries.Values := '=(Tabelle1!R15C3,Tabelle1!R22C3,Tabelle1!R29C3,Tabelle1!R36C3)';
like in VBA it does not work eihter.
I always get an C/AL error, that the "Values" can not be set.
Same it I try to set the Name of Dataseries.
Has anyone any experience with this kond of problem?
Any help is welcome.
Thanks,
Rolf
I create an Excel-Sheet with Navision using Automation-Variables to control Excel.
Creating a Excel-Sheet and fill it with data is not a problem, but now I want to create a chart based on the data in the Excel-Sheet.
I use the following Globals of type Automation:
xlApp: 'Microsoft Excel 11.0 Object Library'.Application
xlWorkbook 'Microsoft Excel 11.0 Object Library'.Workbook
xlWorksheet: 'Microsoft Excel 11.0 Object Library'.Worksheet
xlRange: 'Microsoft Excel 11.0 Object Library'.Range
xlChart: 'Microsoft Excel 11.0 Object Library'.Chart
xlChartObject: 'Microsoft Excel 11.0 Object Library'.ChartObject
xlChartObjects: 'Microsoft Excel 11.0 Object Library'.ChartObjects
xlSeriesCollection: 'Microsoft Excel 11.0 Object Library'.SeriesCollection
xlSeries: 'Microsoft Excel 11.0 Object Library'.Series
Now I use the folloing C/AL-Code to create the chart:
xlChartObjects := xlworksheet.ChartObjects; //Create an instance for automation
xlChartObject := xlChartObjects.Add(xlApp.CentimetersToPoints(15),xlApp.CentimetersToPoints(5),
xlApp.CentimetersToPoints(8),xlApp.CentimetersToPoints(9)); //Create a new chart an place it on the sheet
xlChart := xlChartObject.Chart; // Create an instance for the autoamation
xlChart.ChartType(54); // setting the chart type (54 = 3D Column Clustered)
xlSeriesCollection := xlChart.SeriesCollection; // create an instance for the automation
xlSeries := xlSeriesCollection.NewSeries; // create a new Dataseriens in the chart
Till here everything works fine.
But now I want to "tell" the new Dataseries from where to get the Data, and that's my problem. It does not work.
When recording a Macro in Excel the VBA-Code looks linke this:
ActiveChart.SeriesCollection(1).Values = "=(Tabelle1!R15C3,Tabelle1!R22C3,Tabelle1!R29C3,Tabelle1!R36C3)"
If i use C/AL Code like:
xlSeries.Values := 'C5:C29';
xlSeries.Values := '=C5:C29';
xlSeries.Values := 'Sheet1!C5:Sheet1!C29';
xlSeries.Values := '=Sheet1!C5:Sheet1!C29';
it does not work.
Using
xlSeries.Values := '=(Tabelle1!R15C3,Tabelle1!R22C3,Tabelle1!R29C3,Tabelle1!R36C3)';
like in VBA it does not work eihter.
I always get an C/AL error, that the "Values" can not be set.
Same it I try to set the Name of Dataseries.
Has anyone any experience with this kond of problem?
Any help is welcome.
Thanks,
Rolf
0
Comments
-
I use the following
Range := GetColumnStr(1) + FORMAT(1) + ':' + GetColumnStr(ColumnNo) + FORMAT(RowNo - 1); Sheet.Range(Range).Select; XlRange := Sheet.Range(Range); Book.Charts.Add; Book.ActiveChart.ChartType := 51; Book.ActiveChart.SetSourceData(XlRange,2);
I don't have excel 11 but I think the process should be the same :-k0 -
Hi,
thanks for your response.
If you use "Book.Charts.Add", the charts is inserted on a new Sheet, isn't it?
I need the chart on the same sheet as the Data, and I need it in a specific size and position.
Is it possible (with your method) to add a second "DataSource" to the chart, because I need two DataSeries, which are compared to each other?0 -
Hi Rolf,
It will add the chart to the first worksheet.
I have not tried to get two data ranges but maybe you can then select a second range?
Regards
Albert0 -
Hello
I am using Zet Excel platform
Try it
It helped me a lot !-1 -
huge thanks for your recommendation. do you think that is better than actual Except? is it for free?
i will try it but was wondering if yoou could help me guiding me through its usage. thanks again.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions