chaning color of stacked area at run time

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
NoName
Newbie
Newbie
Posts: 34
Joined: Fri Nov 15, 2002 12:00 am
Location: Italy

chaning color of stacked area at run time

Post by NoName » Wed Mar 24, 2004 8:57 am

Hello,

what I'm describing it's not a problem, but simply an idea I'm searching for.

I have a chart with 4 series: three of them are stacked area, the last one is a line chart.
It is useful to show how my profit is built:
Initial value + Income +/- Gain (or Loss) = Final Value
(first three values are stacked, and final value is a line).

If the third series contains negative values, the stacked bar correctly goes down, over the second stacked bar.
I want to show these "negative areas" in a different color.

I already found a solution: if I set the third area color with a 50% transparency, the color of the third area changes (mix) when it overlaps the second one.

My question is: is there a way, even programmatically, to change the color of the "negative areas", to a solid color I choose, instead of using the transparency?

thank you for your attention.
Chart code here:

Code: Select all

      object Chart3: TChart
        Left = 0
        Top = 0
        Width = 725
        Height = 426
        Legend.Font.Charset = ANSI_CHARSET
        Legend.Font.Name = 'Tahoma'
        Legend.Gradient.Direction = gdBottomTop
        Legend.Gradient.EndColor = 14408667
        Legend.Gradient.MidColor = clWhite
        Legend.Gradient.StartColor = 14408667
        Legend.LegendStyle = lsSeries
        Legend.Shadow.HorizSize = 1
        Legend.Shadow.VertSize = 1
        Legend.VertSpacing = 2
        MarginRight = 6
        Title.Text.Strings = (
          'TChart')
        Title.Visible = False
        BottomAxis.Grid.Color = clSilver
        BottomAxis.Increment = 182
        BottomAxis.MinorTickCount = 0
        BottomAxis.MinorTickLength = 3
        BottomAxis.TickLength = 5
        LeftAxis.Grid.Color = clSilver
        LeftAxis.MaximumOffset = 5
        LeftAxis.MinimumOffset = 5
        LeftAxis.MinorTickCount = 0
        View3D = False
        Zoom.Pen.Color = clRed
        Align = alClient
        Color = clWhite
        TabOrder = 0
        PrintMargins = (
          15
          25
          15
          25)
        object AreaSeries1: TAreaSeries
          Marks.ArrowLength = 8
          Marks.Callout.Brush.Color = clBlack
          Marks.Callout.Length = 8
          Marks.Visible = False
          SeriesColor = 16041064
          Title = 'Initial value'
          AreaLinesPen.Visible = False
          DrawArea = True
          LinePen.Visible = False
          MultiArea = maStacked
          Pointer.InflateMargins = True
          Pointer.Style = psRectangle
          Pointer.Visible = False
          XValues.DateTime = True
          XValues.Name = 'X'
          XValues.Order = loAscending
          YValues.Name = 'Y'
          Data = {
            010600000000000000608CE2400000000000408F40020000008095E240000000
            000068904004000000A09EE2400000000000208C4006000000C0A7E240000000
            0000408F4008000000E0B0E24000000000003091400A00000000BAE240000000
            0000689040}
        end
        object AreaSeries2: TAreaSeries
          Marks.ArrowLength = 8
          Marks.Callout.Brush.Color = clBlack
          Marks.Callout.Length = 8
          Marks.Visible = False
          SeriesColor = 12778393
          Title = 'Income'
          AreaLinesPen.Visible = False
          DrawArea = True
          LinePen.Visible = False
          MultiArea = maStacked
          Pointer.InflateMargins = True
          Pointer.Style = psRectangle
          Pointer.Visible = False
          XValues.DateTime = True
          XValues.Name = 'X'
          XValues.Order = loAscending
          YValues.Name = 'Y'
          Data = {
            010600000000000000608CE2400000000000407F40020000008095E240000000
            0000C0724004000000A09EE240000000000000694006000000C0A7E240000000
            0000208C4008000000E0B0E2400000000000208C400A00000000BAE240000000
            0000508440}
        end
        object AreaSeries3: TAreaSeries
          Marks.ArrowLength = 8
          Marks.Callout.Brush.Color = clBlack
          Marks.Callout.Length = 8
          Marks.Visible = False
          SeriesColor = 6008319
          Title = 'Gain or Loss'
          AreaLinesPen.Visible = False
          DrawArea = True
          LinePen.Visible = False
          MultiArea = maStacked
          Pointer.InflateMargins = True
          Pointer.Style = psRectangle
          Pointer.Visible = False
          Transparency = 50
          XValues.DateTime = True
          XValues.Name = 'X'
          XValues.Order = loAscending
          YValues.Name = 'Y'
          Data = {
            010600000000000000608CE2400000000000006940020000008095E240000000
            0000E0754004000000A09EE240000000000000794006000000C0A7E240000000
            0000C072C008000000E0B0E2400000000000407FC00A00000000BAE240000000
            0000006940}
        end
        object LineSeries1: TLineSeries
          ColorEachLine = False
          Marks.ArrowLength = 8
          Marks.Callout.Brush.Color = clBlack
          Marks.Callout.Length = 8
          Marks.Visible = False
          SeriesColor = clBlue
          Title = 'Final value'
          Dark3D = False
          LinePen.Color = clRed
          LinePen.Width = 2
          Pointer.InflateMargins = True
          Pointer.Style = psRectangle
          Pointer.Visible = False
          XValues.DateTime = True
          XValues.Name = 'X'
          XValues.Order = loAscending
          YValues.Name = 'Y'
          Data = {
            010600000000000000608CE2400000000000909A40020000008095E240000000
            0000909A4004000000A09EE240000000000070974006000000C0A7E240000000
            000000994008000000E0B0E24000000000007097400A00000000BAE240000000
            0000B09D40}
        end
      end

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Wed Mar 24, 2004 10:09 am

Hi.

I think the easiest solution in your case would be to use series OnAfterAdd event to check if series value is positive or negative and then, based on this result, change the point color by accessing it's ValueColor parameter. Pseudo code, placed in series OnAfterAdd event:

Code: Select all

if Sender.YValues[ValueIndex] >= 0 then Sender.ValueColor[ValueIndex] := clGreen
else
Sender.ValueColor[ValueIndex] := clRed;
Marjan Slatinek,
http://www.steema.com

NoName
Newbie
Newbie
Posts: 34
Joined: Fri Nov 15, 2002 12:00 am
Location: Italy

Post by NoName » Wed Mar 24, 2004 1:21 pm

Great, it works!

now I have just to fine-tuning one more thing: with the AfterAdd event, the color changement is ok, except for the last value before sign changes.

That is, if I have values 10,20,30,-10,-20 and I want positive in green, and negative in red, the first two values are in green, then there are three reds.
Anyway, I'll try to workaround this problem.

Thank you for your suggestion!

Post Reply