Recent

Author Topic: [SOLVED] TAChart first steps (3d, labels...)  (Read 2287 times)

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
[SOLVED] TAChart first steps (3d, labels...)
« on: June 15, 2020, 01:56:28 pm »
Hi,

I am giving my first steps with the TAChart, series, etc controls. I have been able (https://wiki.lazarus.freepascal.org/TAChart_documentation) to create different kind of charts and series. But I would need some help with the following:


1) How I switch from 2d to 3d view in a pie chart? This code does not work:
Code: Pascal  [Select][+][-]
  1. // code to switch to 2d
  2. (...)
  3. Chart1PieSeries1.Depth:=0;
  4. Chart1PieSeries1.Orientation:=poNormal; // don't know how to do this :=pNormal? :=[pNormal]? Chart1PieSeries1.Orientation.poNormal? None works
  5. // poNormal is an enumerator type
  6. (...)
  7. // code to switch to 3d
  8. Chart1PieSeries1.Depth:=15;
  9. Chart1PieSeries1.Orientation.poHorizontal;
  10. (...)
  11.  

2) I know It is possible to label marks in an x axis with month names (i.e: to chart monthly expenses) but how?? I don't seem to find an example. I need to divide the x axis in 12 portions and label them. There's something I have missed to read somewhere.

3) It is possible to click one portion of a pie to slice it out? To create a kind of animation effect.


regards,
« Last Edit: June 16, 2020, 02:06:12 pm by Raul_ES »
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

wp

  • Hero Member
  • *****
  • Posts: 13418
Re: TAChart first steps (3d, labels...)
« Reply #1 on: June 15, 2020, 03:04:48 pm »
(1) 3D in TAChart is kind of "fake", there is not "hidden line/hidden area" algorithm", and there are situation where it looks really wrong. But I spent a lot of time with the Pie series, and it looks almost always correct.

The key parameter is, as you noticed, the Depth property, it defines the length if the in-depth lines connecting the font and back images of the series (in pixels)

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Toggle3D;
  2. begin
  3.   if PieSeries.Depth = 0 then PieSeries.Depth := 25 else PieSeries.Depth := 0;
  4. end;

Using the "Orientation" requires Lazarus trunk, it is not yet contained in the current releases. It defines how the pies are oriented with respect to the viewer. poNormal has the circle upright like a wheel, poVertical, too, but the viewing direction is more oblique. in poHorizontal the wheel lies flat on the floor.

(2) To label the x axis with strings you must assign a chartsource to the xaxis.Marks.Source and set xaxis.Marks.Style to smsLabel. For example, when you have 12 expense values (one each per month) you can add the data to the series like this (there are many other ways...):
Code: Pascal  [Select][+][-]
  1. series.AddXY(1, expenses_Jan, 'Jan');
  2. series.AddXY(2, expenses_Feb, 'Feb');
  3. ...
This way the data points are stored in the internal "ListSource of the series, and you added a text value to each data point. You can assign the series.ListSource to the xAxis.Marks.Source as noted to see the labels at runtime.

Alternatively, you can add a separate TListChartSource to the form and put the month numbers and names in there. I added a demo to show this.

(3) TPieSeries is a bit special. It normally has only Y values which, normalized to 360 degrees, are the opening angles of the pies. When X is 0 then the pies are centered. But when x of a pie is greater than 0 then the pie moves away from the center. Note however, that x is measured in units of the pie radius, i.e. when x is 0.1 (a good value) the pie would be offset by 1/10th of the radius.

Code: Pascal  [Select][+][-]
  1. PieSeries.AddXY(0,   1000, 'Jan');
  2. PieSeries.AddXY(0,   1100, 'Feb');
  3. PieSeries.AddXY(0,    950, 'Mar');
  4. PieSeries.AddXY(0.1, 1200, 'April');   // <--- 0.1 --> Pie will be offset by 10% of the pie radius
  5. PieSeries.AddXY(0,   1030, 'May');
  6. ...

There is a pie series demo in folder (lazarus)/components/tachart/demo/radial of your Lazarus installation. It demonstrates also how a pie can be offset by clicking with the mouse.

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TAChart first steps (3d, labels...)
« Reply #2 on: June 16, 2020, 12:47:37 am »
Thank you very much wp,

(3) and (2) have been solved. And thanks for your clear source code. Sometimes reading so much documentation online becomes disturbing and confusing.
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TAChart first steps (3d, labels...)
« Reply #3 on: June 16, 2020, 12:55:42 am »
I don't fully understand (1).

I actually use CodeTyphon 7.0 and the TAChart component TPieseries I believe it really supports the Orientation property. Let me show you some images from the IDE, check the attachments please.

Picking poNormal, poVertical and poHorizontal from the Object Inspector seems to work. Isn't supposed to then work also on run-time? Let me ask the question again: what would be the right pascal sentence to change Orentation property of the pie at run-time?

thanks
« Last Edit: June 16, 2020, 01:16:49 am by Raul_ES »
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

wp

  • Hero Member
  • *****
  • Posts: 13418
Re: TAChart first steps (3d, labels...)
« Reply #4 on: June 16, 2020, 11:59:25 am »
In 2D mode there is only a single Orientation. In 3D mode you set

Code: Pascal  [Select][+][-]
  1. Chart1PieSeries1.Depth:=20;
  2. Chart1PieSeries1.Orientation:=poNormal;  // or poVertical or poHorizontal, requires unit TARadialSeries

In the attachement there is another demo, now for the PieSeries.

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TAChart first steps (3d, labels...)
« Reply #5 on: June 16, 2020, 12:30:04 pm »
thanks wp,

I missed putting the right unit (taradialseries) inside the uses paragraph. Now it works as expected.

regards
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

 

TinyPortal © 2005-2018