Recent

Author Topic: Different colors for one lineseries with 3 y-values?  (Read 3125 times)

wittbo

  • Full Member
  • ***
  • Posts: 150
Different colors for one lineseries with 3 y-values?
« on: January 18, 2018, 07:23:46 am »
I have one lineseries containing 3 Y-values. When setting the color for the series, then all three lines get the same color, is it possible to assign different colors to the lines corresponding to the three y-values or do I have to choose three different lineseries?
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Different colors for one lineseries with 3 y-values?
« Reply #1 on: January 18, 2018, 09:18:48 am »
You should add a TChartStyles component and assign it to the "Styles" of the series. Right-click on the Styles component and add three items - each one of them corresponds to a line of the multi-valued series, set its Pen accordingly.

See also http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Stacked_BarSeries#Using_ChartStyles.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Different colors for one lineseries with 3 y-values?
« Reply #2 on: January 18, 2018, 09:43:14 am »
If you want to display a legend item for each of the y values you must enter the legend text in the element Text of its corresponding Style item, and the LegendMultiplicity of the series must be set to lmStyle.

Please note that the current version of TAChart crashes here. Use the trunk version of Lazarus where I fixed this a minute ago. Or apply the fix manually:
  • Open TASeries.pas (in (lazarus)/components/tachart)
  • Find the implementation of procedure TLineSeries.GetLegendItems.
  • Add "lb: TBrush" to the "var" declarations.
  • Modify the case "lmStyle" of Legend.Multiplicity to become
Code: Pascal  [Select][+][-]
  1. var
  2.   lb: TBursh;   // <--- ADD
  3. ...
  4.   case Legend.Multiplicty of
  5. ...
  6.     lmStyle:
  7.       if Styles <> nil then begin    // <-- ADD "begin"
  8.         if Assigned(p) then lb := p.Brush else lb := nil;   // <--- ADD
  9.         for s in Styles.Styles do
  10.           AItems.Add(TLegendItemLinePointer.CreateWithBrush(
  11.             IfThen((lp <> nil) and s.UsePen, s.Pen, lp) as TPen,
  12.             IfThen(s.UseBrush, s.Brush, lb) as TBrush,   // <--- USE "lb" instead of "p.Brush"
  13.             p,
  14.             LegendTextStyle(s)
  15.           ));
  16.       end;    // <--- ADD
   

 

TinyPortal © 2005-2018