Recent

Author Topic: [SOLVED] How to Custom pointer glyph depending of the Z value  (Read 4127 times)

barsoom

  • Jr. Member
  • **
  • Posts: 51
After to take a look to the Tachart demo "linedemo", i showed that it is possible to use a bmp file as the pointer in line series. I also saw in the same demo that it is possible to change the pointer style among the default ones.

However, i am interested on show, in all points, a different glyph depending of the value Z of the serie, taking it from a imagelist. Let me explain with detail:

I have a serie with values X, Y and Z. They are plotted in a chart based on X and Y values. On the other hand, Z values could range, lets say, between 1 and 5, for example. Then, i could like to show not the lines, but points only. However, i would like to use a different image depending of the Z value... better than a different pointer style. The glyphs could be stored into a imagelist or chartimage list (i do not know what is the better option, if it is feasible).

Is it possible? I am lost about how to start to solve this. I can imaging that it cpould be something based on "lsCumtomDrawPointerCustomdrawPointer" and "lsGerpointerStyleGetPointerStyle" procedures of LineDemo, but i can see how to go ahead.

Thanks in advance.

« Last Edit: July 13, 2021, 05:00:12 pm by barsoom »

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: How to Custom pointer glyph depending of the Z value
« Reply #1 on: July 13, 2021, 12:49:02 am »
Maybe the attached demo is simpler. It has 10 bitmaps in an image list. The y value ranges between 0 and 10. The image index simply is obtained by taking the integer part of the y values. And then the OnCustomDrawpointer event is used to paint these bitmaps instead of the standard pointer symbols.

barsoom

  • Jr. Member
  • **
  • Posts: 51
Re: How to Custom pointer glyph depending of the Z value
« Reply #2 on: July 13, 2021, 02:58:21 pm »
Much easier. Thanks @wp!
It is almost what i need, so your code get me in the direct path to the solution. Thanks a lot!!!


« Last Edit: July 13, 2021, 03:06:04 pm by barsoom »

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: How to Custom pointer glyph depending of the Z value
« Reply #3 on: July 13, 2021, 03:11:32 pm »
Do you have the Windows unit in your uses clause? Because it declares a TBitmap of its own. You need the TBitmap declared in the graphics unit. To achieve this you must put the Windows unit in front of the uses list, at least before the graphics unit. Alternatively you can fully qualify the TBitmap type used here by putting a "Graphics." (with trailing point at the end) in front of "TBitmap":  "TBitmap" --> "Graphics.TBitmap"
Code: Pascal  [Select][+][-]
  1.  procedure TForm1.WeatherSerieCustomDrawPointer(ASender: TChartSeries;
  2.       ADrawer: IChartDrawer; AIndex: Integer; ACenter: TPoint);
  3.      
  4.       procedure DoDrawPointer(ABitmap: Graphics.TBitmap);
  5.         var
  6.           img: TLazIntfImage;
  7.           //ser: TLineSeries;
  8.         begin
  9.           img := TLazIntfImage.Create(0,0);
  10.           try
  11.             img.LoadFromBitmap(ABitmap.Handle, ABitmap.MaskHandle);
  12.             ADrawer.PutImage(ACenter.X - ABitmap.Width div 2, ACenter.Y - ABitmap.Height div 2, img)
  13.           finally
  14.             img.Free;
  15.           end;
  16.         end;
  17.      
  18.     var
  19.       imgIndex: Integer;
  20.       bmp: Graphics.TBitmap;
  21.     begin
  22.       imgIndex := trunc(ASender.GetYValue(AIndex));
  23.       bmp := Graphics.TBitmap.Create;
  24.       ImageList5.GetBitmap(imgIndex, bmp);
  25.       DoDrawPointer(bmp);
  26.       bmp.Free;
  27.     end;

barsoom

  • Jr. Member
  • **
  • Posts: 51
Re: How to Custom pointer glyph depending of the Z value
« Reply #4 on: July 13, 2021, 03:19:46 pm »
You were so fast!!!
I found the problem and solved before to edit my reply to delete the problem.

In any case, but your answer it quite useful to other in the same case.
Thanks again @wp!

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: How to Custom pointer glyph depending of the Z value
« Reply #5 on: July 13, 2021, 03:31:41 pm »
I should also have mentioned the following: i know that Delphi adds the Windows unit to almost every unit although it is not needed. Therefore my final hint: remove the Windows unit - there's a high chance that the programm will run. If it does not use LCLIntf and LCLType instead of Windows. Doing so will keep your program cross-platform.

barsoom

  • Jr. Member
  • **
  • Posts: 51
Re: How to Custom pointer glyph depending of the Z value
« Reply #6 on: July 13, 2021, 04:59:12 pm »
Thanks so much again @wp.

I finally was able to do what i had on mind. Since i do not want to use the Y value of each point to define the symbol, i used the color property.

Then, when added the values to the series, i did this:
Code: Pascal  [Select][+][-]
  1. WeatherSerie.AddXY(x, y,'',z);
where z is the value i want to use to define the symbol to be used, i store as if it was the color propertie of each point.

In your code, i made this small change:
Code: Pascal  [Select][+][-]
  1. imgIndex :=ASender.GetColor(AIndex);

so... SOLVED! Thanks @wp!

 

TinyPortal © 2005-2018