Solved

Controlling advanced features of Charts in a TExcelApplication

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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