Forum > TAChart

Adding event to runtime-created series

(1/2) > >>

bobby100:
Hi @all,

I wrote a little app for drawing charts. That is something new, isn't it?  :D
I am adding and editing series at runtime. Today I was gone for implementing the rendering over BGRA.
In order to get runtime-created TBarSeries rendered as ChocolateBar, I need to assign an event-handler, and that is the step where I got stuck.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain.AddSeries;var  ser: TBasicChartSeries;.. begin ... if ser is TBarSeries then    begin      //this code gets executed      TBarSeries(ser).OnBeforeDrawBar := @BeforeDrawBarHandler;    end;    Chart.AddSeries(ser);  ....  procedure TfrmMain.BeforeDrawBarHandler(ASender: TBarSeries;  ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: integer;  var ADoDefaultDrawing: boolean);begin  //this code never execute  ADoDefaultDrawing := False;  DrawChocolateBar(ASender, ACanvas, ARect, APointIndex, True);end;  
Any idea what I am doing wrong?

The app is based on the demos for TAChart with the addition of saving the whole work to file, copy the graph to the clipboard.
Screenshot is attached (just an example without much sense)

If the app gets usable, I will be glad to share it here.

wp:
You do not say what's the problem...

Comparing your code snippet with the bgra demo in the TAChart demo folder I see that you assign an event handler to OnBeforeDrawBar, but in the demo there is a handler for OnCustomDrawBar.

bobby100:
Hi wp,

the problem is that the event does not get triggered - it remains the default rendering. It does not render through BGRA. Take a look at the comments in the code.

As for the TAChart demo - there are examples for both OnBeforeDrawBar and OnCustomDrawBar. In TAChart tutorial on the Wiki is also OnBeforeDrawBar.

Do I need to initialize something in order to get BGRA rendering?

wp:
Thanks for bringing my attention to this.

The OnBeforeDrawBar event of the TBarSeries has been deprecated for some time and has been replaced by the OnCustomDrawBar event. This new event is more flexible regarding the drawing backends (ChartDrawer).

In the transition time before the OnBeforeDrawBar event will be removed finally, both events will be available, but the OnBeforeDrawBar handler will be executed only when no OnCustomDrawBar handler is attached. Unfortunately I had forgotten to remove the old OnBeforeDrawBar code from the demo - just did this in the current Lazarus/main version.

I also updated the wiki tutorial about TAChart and BGRA (https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_TAChart).

bobby100:
Thanks, but it didn't help.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain.BeforeDrawBarHandler(ASeries: TBarSeries;  ADrawer: IChartDrawer; const ARect: TRect; APointIndex, AStackIndex: Integer);var  ic: IChartTCanvasDrawer;begin  if not Supports(ADrawer, IChartTCanvasDrawer, ic) then    raise Exception.Create('This program requires a canvas drawer.');  DrawPhong3DBar(ASeries, ic.Canvas, ARect, APointIndex);end;  
This code gives the exception 'This program requires a canvas drawer'.
I use Lazarus 2.2.0 RC2. Is that the source of my problem?

Navigation

[0] Message Index

[#] Next page

Go to full version