Recent

Author Topic: Changing color in a TAChart LineSeries  (Read 10297 times)

jhmos

  • New Member
  • *
  • Posts: 24
Changing color in a TAChart LineSeries
« on: March 17, 2011, 04:15:42 am »
I want to change color of the line plot depending on the value of the item in the series.
I tried to use UserDefinedChartSource GetChartDataItem, setting AItem.Color like this:
Code: [Select]
procedure TTRecForm.UserDefinedChartSource1GetChartDataItem(
  ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
begin
  AItem.X:= AIndex;
  AItem.Y:= CurrentTemperatureLog[AIndex];
  AItem.Color:= clBlack;
  if AItem.Y > 30.0 then
    AItem.Color:= clRed;
  if AItem.Y < 10.0 then
    AItem.Color:= clBlue;
end;
But it looks like the Color property does not get used from there, I only get the colour that was set before the graph gets drawn (from LineSeries.SeriesColor or LineSeries.LinePen.Color).

What would be the best way of changing color in a line plot using TAChart?

I am using a 0.9.29 snapshot build under 64bit Ubuntu.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Changing color in a TAChart LineSeries
« Reply #1 on: March 17, 2011, 09:17:00 am »
Color form the data source is used for drawing points, not lines
(try setting ShowPoints = true to see it).

Quote
What would be the best way of changing color in a line plot using TAChart?
If you give a general enough specification, I am ready to implement it.
Which line segment should use the color from the data point?
Previous one? Next one? Half of both?
How should it interact with 3D lines?

jhmos

  • New Member
  • *
  • Posts: 24
Re: Changing color in a TAChart LineSeries
« Reply #2 on: March 17, 2011, 04:11:14 pm »
I did also try showing points, but the colour of each Series item didn't get used for drawing the points either, only the value already set in LineSeries.Pointer.Pen.Color. Is there some trick that I'm missing?

I see what you mean about choosing the colour of the line segment. For my application (when I have just drawn plots in a TImage.Canvas), I chose to have the line take the colour of the destination point but that was fairly arbitrary. Ideally I would change colour at a threshold (an alarm temperature in my case), which might mean dividing the line between two points into 2 segments. Maybe applications like that would be getting too specific for TAChart and I have given no consideration to 3D lines.

Having point colour working would probably be enough for me.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Changing color in a TAChart LineSeries
« Reply #3 on: March 17, 2011, 04:34:57 pm »
Quote
I did also try showing points, but the colour of each Series item didn't get used for drawing the points either, only the value already set in LineSeries.Pointer.Pen.Color. Is there some trick that I'm missing?

No, it should work. I just tested it and it works for me (see basic demo since r29893).
Please post an example project demonstrating your problem.

Quote
Ideally I would change colour at a threshold (an alarm temperature in my case)
Interesting. How would you set the thresholds? Separate ThresholdSource?
I shall think about it -- meanwhile, are you aware of any other
charting libraries that provide similar functionality?
If you find such a library, it might serve both as an indicator of non-zero
user base and an API guideline for this feature.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Changing color in a TAChart LineSeries
« Reply #4 on: March 19, 2011, 01:57:02 pm »
Quote
Ideally I would change colour at a threshold (an alarm temperature in my case)

Independently of the line series, you can use axis stripes to achieve similar effect.
See axistransform demo, "Logarithm" page for an example.

jhmos

  • New Member
  • *
  • Posts: 24
Re: Changing color in a TAChart LineSeries
« Reply #5 on: March 22, 2011, 06:43:40 am »
Independently of the line series, you can use axis stripes to achieve similar effect.
See axistransform demo, "Logarithm" page for an example.
Thanks, I'll have a look at that. I found what was going wrong with Pointer drawing. I had set the point horizontal and vertical size to 1 (to make it look more like a line), which displayed nothing, both have to be at least 2 pixels to display anything.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Changing color in a TAChart LineSeries
« Reply #6 on: March 23, 2011, 07:46:11 am »
Quote
I had set the point horizontal and vertical size to 1 (to make it look more like a line), which displayed nothing, both have to be at least 2 pixels to display anything.

Since r29988, I have added "Pointers" page to the line demo.
It does display all pointer sizes for me on Windows.
Can you please run this demo, set "Size" to 1, and post a screenshot?

 

TinyPortal © 2005-2018