Solved

Controlling advanced features of Charts in a TExcelApplication

Posted on 2004-10-15
5
646 Views
Last Modified: 2010-05-18
Hi Experts,

I've got the following problem: I'm drawing a chart on an excelsheet and want to change some features of it, like the minimum and maximum values of the axes. I have no idea how to do that though. The chart does work with the proper values, it's the make-up that's giving me problems. Any help here is appreciated.
Here's what I've got so far:

                 iNoFields := 8;        // Source-Collumn
                 iEindGraph := iNoRows; // End Source-Row     iBeginGraph = Begin Source-Row
                 vCellStart := Format('%s%d', [Char(iNoFields + 64), iBeginGraph]);
                 ExcelApp.WorkBooks.Item[IIndex].Sheets.Add(EmptyParam, EmptyParam, 1, xlChart, 0); // Add a Chart to the Workbook
                 iNoRows := iNoRows + 1;
                 WorkBk.ActiveChart.ChartType := xlBarClustered;
                 WorkBk.ActiveChart.SetSourceData(Worksheet.Range[vCellStart,Worksheet.Cells.Item[iEindGraph,iNoFields]], xlColumns); // Assign values to the chart
                 WorkBk.ActiveChart.Location(xlLocationAsObject, 'Blad1'); // Assign the Chart to the Worksheet called : Blad1
                 WorkBk.ActiveChart.Axes(xlValue, EmptyParam, 1).MaximumScale := 400;
// This part isn't working.


TIA

Jaco
0
Comment
Question by:jacohoff
  • 2
5 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 12331961
Did you try recording a macro with your chart building? You will encounter there these lines:

    Charts.Add
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A3:B11"), PlotBy _
        :=xlColumns
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Val"
        .Axes(xlCategory, xlPrimary).HasTitle = False
        .Axes(xlValue, xlPrimary).HasTitle = False
    End With
    ActiveChart.HasLegend = False
    ActiveChart.HasDataTable = False
    ActiveSheet.Shapes("Chart 3").IncrementLeft -75.75
    ActiveSheet.Shapes("Chart 3").IncrementTop -117.75
    ActiveChart.Axes(xlValue).Select
    With ActiveChart.Axes(xlValue)
        .MinimumScale = 555
        .MaximumScale = 777
        .MinorUnitIsAuto = True
        .MajorUnitIsAuto = True
        .Crosses = xlAutomatic
        .ReversePlotOrder = False
        .ScaleType = xlLinear
        .DisplayUnit = xlNone
    End With




Now all you have to do is try to convert these lines to delphi... It's a little tricky but I'm sure you'll figure it out.
Right now I don't have time to do it for you. If you can't do it tell me and in the next couple of days I will try to solve it for you

        .MinimumScaleIsAuto = False
        .MaximumScaleIsAuto = False

Maybe you should try setting the above for the cahart axis to see what happens. Because theoretically if it is auto it wouldn't matter the values you set as max and min, because it would be autmatic all the time. So probabely your problem comes from that auto property
0
 

Author Comment

by:jacohoff
ID: 12345636
Hello,

First of all a small reaction on the last few lines.

Delphi (6) doesn't seems to know these kind of parameters. Most of the time you can just copy and paste the VB-source in Delphi, with just some minor changes. But Delphi just won't accept these kind of parameters.

It might be a sollution building a Macro from Delphi, but that won't win the beauty price.

If someone has a better sollution let me know.

TIA.
0
 

Author Comment

by:jacohoff
ID: 12442560
Hello,

The problem has been solved...

The reason Delphi wouldn't accept parameters like MinimumScale, MaximumScale was because thay weren't defined in the delphi source-files for Excel.

The solution was to add a variant which also was pointed to the Excel workbook.

After this variant you can add all the parameters in the way you see them in the macro's in VB-Script.

Add this line to Var :
     WkBook : variant;

Add this line after ExcelApp.Workbooks.Add(xlWBatWorkSheet,0);
     WkBook := ExcelApp.WorkBooks.Item[IIndex];

Now you can copy and paste the source according to VB-Script between:
with WkBook do
begin
...
end;

It seems the Variant is a bit slower than using _WorkBook, because the parameters are not checked at designtime but at run-time. So I only use it for graphics and other parameters which aren't availible otherwise.

Thanks for the help.
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 12478890
Closed, 250 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 207
Create Database on Android via Delphi dbExpress 3 81
Making delphi communicate with a c# service 16 90
Convert MS Word document to a PDF file 9 64
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now