简体   繁体   中英

Delphi 7 creating tChart Bar Pyramids / Cylinders at run-time

I know - Delphi 7 is prehistoric and tChart is not the best. But I must use them, so...

I can change the type of the series at run-time with

var cs: tChartSeries;
begin
  cs := chart.Series[0];
  ChangeSeriesType(cs, TBarSeries);
end;

And I discovered most of them: tLineSeries, tBarSeries, tAreaSeries, tPointSeries,...

Unfortunately, I cannot find how to set it to Bar/Pyramids and Bar/Cylinders. If I try to create them at run-time, I see that the wizard calls them "Style", but if I try

chart.series[0].Style := …

that property (of type tChartSeriesStyles) refers to different things. Just for future references and because it was hard to find:

TChartSeriesStyle = set of ( tssIsTemplate, 
                             tssDenyChangeType, 
                             tssDenyDelete, 
                             tssDenyClone, 
                             tssIsPersistent, 
                             tssHideDataSource ); 

So, the question is: how can I change, at run-time, a Delphi 7 tChart serie to "pyramid" and "cylinder"?

Thank you

In Delphi 10.3 setting up a pyramid styled bar chart manually in the IDE and viewing the DFM as text gets a section like:

  object Chart1: TChart
    Left = 224
    Top = 136
    Width = 400
    Height = 250
    Title.Text.Strings = (
      'TChart')
    TabOrder = 0
    DefaultCanvas = 'TGDIPlusCanvas'
    ColorPaletteIndex = 13
    object Series2: TBarSeries
      BarStyle = bsPyramid
      XValues.Name = 'X'
      XValues.Order = loAscending
      YValues.Name = 'Bar'
      YValues.Order = loNone
    end
  end

Can try doing the same in Delphi 7 and see what properties get set to what values.

In Delphi 10.3 in code it ends up like (assuming Series2 is a TBarSeries):

  Series2.BarStyle := bsPyramid;

You need to "cast" that serie to a tBarSeries and THEN you can change the value. Example:

(c.series[0] as tBarSeries).BarStyle := bsPyramid;
(c.series[1] as tBarSeries).BarStyle := bsCilinder;

Since it looks like it's not documented anywhere, simply type "bs" and press CTRL-SPACE to see all the possible values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM