Solved

Controlling advanced features of Charts in a TExcelApplication

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now