Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Controlling advanced features of Charts in a TExcelApplication

Posted on 2004-10-15
5
Medium Priority
?
689 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

661 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