Recent

Author Topic: BoxChart cannot be color coded  (Read 1656 times)

kiyo

  • Newbie
  • Posts: 6
BoxChart cannot be color coded
« on: May 31, 2023, 03:17:15 am »
BoxChart cannot be color coded

Add 5 BoxAndWshiskerSeries to the TChart and color code them.

Chart1BoxAndWhiskerSeries1.BoxBrush.Color := clBlue;
Chart1BoxAndWhiskerSeries2.BoxBrush.Color := clYellow;
Chart1BoxAndWhiskerSeries3.BoxBrush.Color := clRed;
Chart1BoxAndWhiskerSeries4.BoxBrush.Color := clGreen;
Chart1BoxAndWhiskerSeries5.BoxBrush.Color := clAqua;

In the Legend display, the 5 Legends are correctly color-coded.
But in MainChart,all BoxChart become clBlue.

In this case, ChartColor has no way of knowing which Box is which data.
How can I fix it?

OS:Windows10 pro, Lazarus Version:2.2.0

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: BoxChart cannot be color coded
« Reply #1 on: May 31, 2023, 10:10:50 am »
Without seeing your code, I speculate that you added all values to the first series. The other series are empty but nevertheless listed in the legend.

There are two options:
- Use only one series to which you add all data points and specify the color in the AddXY call (the BoxBrush is ignored in this case)
Code: Pascal  [Select][+][-]
  1.   Chart1BoxAndWhiskerSeries1.AddXY(0, 1, 2, 3, 4, 5, '', clBlue);
  2.   Chart1BoxAndWhiskerSeries1.AddXY(1, 2, 3, 4, 5, 6, '', clYellow);
  3.   Chart1BoxAndWhiskerSeries1.AddXY(2, 2.5, 3.1, 3.9, 5.1, 5.9, '', clRed);
- Or use a dedicated series for each single data point, do not use the AddXY color, but control the color by the BoxBrush property
Code: Pascal  [Select][+][-]
  1.   Chart1BoxAndWhiskerSeries1.AddXY(0, 1, 2, 3, 4, 5);
  2.   Chart1BoxAndWhiskerSeries2.AddXY(1, 2, 3, 4, 5, 6);
  3.   Chart1BoxAndWhiskerSeries3.AddXY(2, 2.5, 3.1, 3.9, 5.1, 5.9);

kiyo

  • Newbie
  • Posts: 6
Re: BoxChart cannot be color coded
« Reply #2 on: May 31, 2023, 08:35:05 pm »
I was able to solve the problem.
I am amazed at your insight.
Thanks for the good advice.

 

TinyPortal © 2005-2018