Solved

Controlling advanced features of Charts in a TExcelApplication

Posted on 2004-10-15
5
661 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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