* * *

Author Topic: primary Questions about TChart  (Read 1120 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 313
primary Questions about TChart
« on: February 09, 2018, 07:31:31 pm »
Hi

i have many primary Questions  about TChart.

please help and guide me

how can i fix min and max axis ?

how can i have mult color line?

how can i change value of X axis to Srtinf Text?

how can i show value of point?

« Last Edit: February 09, 2018, 07:35:39 pm by majid.ebru »

majid.ebru

  • Sr. Member
  • ****
  • Posts: 313
Re: primary Questions about TChart
« Reply #1 on: February 09, 2018, 07:32:29 pm »
and

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #2 on: February 09, 2018, 08:08:06 pm »
how can i fix min and max axis ?
Set the Extent of the chart (can be done by code like below, or directly in the Object Inspector)
Code: Pascal  [Select]
  1.   Chart1.Extent.YMax := 100;
  2.   Chart1.Extent.YMin := 0;
  3.   Chart1.Extent.UseYMax := true;
  4.   Chart1.Extent.UseYMin := true;

how can i change value of X axis to Srtinf Text?
What you probably need is an event handler for the event OnMarkToText of the axis. Example
Code: Pascal  [Select]
  1. procedure TForm1.Chart1AxisList1MarkToText(var AText: String; AMark: Double);
  2. begin
  3.   if AMark = 0.0 then AText := 'zero';
  4. end;

how can i show value of point?
Set the Marks.Style of the series to smsValue. The settings of Marks.Style define the combinations of the data point parameters (x, y, text) which will be shown as datapoint label (http://wiki.lazarus.freepascal.org/TAChart_documentation#Mark_labels):
Code: Pascal  [Select]
  1. type
  2.   TSeriesMarksStyle = (
  3.     smsCustom,         { user-defined }
  4.     smsNone,           { no labels }
  5.     smsValue,          { 1234 }
  6.     smsPercent,        { 12 % }
  7.     smsLabel,          { Cars }
  8.     smsLabelPercent,   { Cars 12 % }
  9.     smsLabelValue,     { Cars 1234 }
  10.     smsLegend,         { ? }
  11.     smsPercentTotal,   { 12 % of 1234 }
  12.     smsLabelPercentTotal, { Cars 12 % of 1234 }
  13.     smsXValue);        { 21/6/1996 }    
Change the format string in Marks.Format to limit the number of decimal places, e.g. '%.2f' for 2 decimals only.

I'll have to think about the other questions.
- What does the last image (06.png) mean?
- In image 05.png you have a chart with a line series, and there's a horizontal dividing line. The parts of the line series above the dividing line should be painted in a different color than the parts below the dividing line. Correct? Will be dividing line be fixed, or should it be user-changeable?
« Last Edit: February 09, 2018, 10:14:03 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

taazz

  • Hero Member
  • *****
  • Posts: 4776
Re: primary Questions about TChart
« Reply #3 on: February 09, 2018, 08:16:55 pm »
how can i have mult color line?
There is no reason for multi colour lines. lines are not part of the data only points are the data lines are there to sombolize an idea only it is either negative or positive it can't be both. Don't waste your time on a illogical case.
how can i show value of point?
select the series of the chart and change the marks.style to what ever you need make sure that the marks are visible.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #4 on: February 09, 2018, 09:48:13 pm »
how can i have mult color line?
Drawing the segments of a lineseries in different colors is not supported. But you can use a TUserDrawnSeries instead of the TLineSeries in which you can draw whatever you want - see attached demo.
  • FormCreate defines some dummy data in an array of TDataRec records (record of x and y values) and calculates the range covered by the x and y values (Extent)
  • The Extent has to be passed to the series in its event OnGetBounds.
  • The event OnDraw expects code which paints the entire series. My code simply iterates through the data point array, calculates the image coordinates of each data point (by calling the chart's method GraphToImage) and draws the line segments in the color which is assigned to the current point index in the COLORS array. I should mention that using a Canvas in the OnDraw event is not up to the standard of TAChart which has introduced dedicated drawers. But there's nothing else at the moment, and you hopefully do not want to paint on exotic output devices.
This probably is also the way to answer the question related to image 05.png where the series changes color above and below a dividing line. The only code which has to be added is the calculation of the intersection point of the line segment with the dividing line.
« Last Edit: February 09, 2018, 10:05:39 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #5 on: February 09, 2018, 10:01:53 pm »
how can i have mult color line?
There is no reason for multi colour lines. lines are not part of the data only points are the data lines are there to sombolize an idea only it is either negative or positive it can't be both. Don't waste your time on a illogical case.
I don't quite understand what you mean, but I could imagine several use cases of multi-colored line segments. For example to highlight segments for which the slope exceeds a given limit. Or - if the series displays a road - the color symbolizes the number of accidents on each segment.
« Last Edit: February 09, 2018, 10:07:30 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #6 on: February 10, 2018, 09:52:01 pm »
how can i have mult color line?
The TLineSeries of TAChart in Lazarus trunk, r57277, now has a new property "ColorEach" with which you can colorize the line segments individually. The color is added to the data points (4th parameter of the series method AddXY) and can be applied to data points symbol and/or the line segments before or after each data point (TColorEachMode = (ceNone, cePoint, ceLineBefore, ceLineAfter, cePointAndLineBefore, cePointAndLineAfter).

See the demo in the TAChart demo folder (lazarus/components/tachart/demo/line)
« Last Edit: February 10, 2018, 10:57:05 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #7 on: February 11, 2018, 12:18:42 am »
In the attachment there is a solution to the "color-split" chart. It is based on the user-drawn series as described above. Drag the horizontal dividing line up and down to move the color boundary. There's a little glitch, when data point symbols are shown and the dividing line goes right through the symbol because the symbol is always drawn as a full circle - to get over this a clipping approach should be used.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

majid.ebru

  • Sr. Member
  • ****
  • Posts: 313
Re: primary Questions about TChart
« Reply #8 on: February 11, 2018, 07:29:39 am »
In the attachment there is a solution to the "color-split" chart. It is based on the user-drawn series as described above. Drag the horizontal dividing line up and down to move the color boundary. There's a little glitch, when data point symbols are shown and the dividing line goes right through the symbol because the symbol is always drawn as a full circle - to get over this a clipping approach should be used.

Thankyou

your project is very Goooooooood

but i can't compile your project?

waht do i do?

i should update my TChart element?

majid.ebru

  • Sr. Member
  • ****
  • Posts: 313
Re: primary Questions about TChart
« Reply #9 on: February 11, 2018, 07:31:07 am »
how can i have mult color line?
The TLineSeries of TAChart in Lazarus trunk, r57277, now has a new property "ColorEach" with which you can colorize the line segments individually. The color is added to the data points (4th parameter of the series method AddXY) and can be applied to data points symbol and/or the line segments before or after each data point (TColorEachMode = (ceNone, cePoint, ceLineBefore, ceLineAfter, cePointAndLineBefore, cePointAndLineAfter).

See the demo in the TAChart demo folder (lazarus/components/tachart/demo/line)

it's perfect

how can i do that?

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #10 on: February 11, 2018, 10:49:35 am »
In the attachment there is a solution to the "color-split" chart. It is based on the user-drawn series as described above. Drag the horizontal dividing line up and down to move the color boundary. There's a little glitch, when data point symbols are shown and the dividing line goes right through the symbol because the symbol is always drawn as a full circle - to get over this a clipping approach should be used.

Thankyou

your project is very Goooooooood

but i can't compile your project?

waht do i do?

i should update my TChart element?
It seems that you don't use Laz 1.8. You should upgrade, there are many new features.

If you don't want to, just remove the line causing the trouble.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4203
Re: primary Questions about TChart
« Reply #11 on: February 11, 2018, 11:48:16 am »
how can i have mult color line?
The TLineSeries of TAChart in Lazarus trunk, r57277, now has a new property "ColorEach" with which you can colorize the line segments individually. The color is added to the data points (4th parameter of the series method AddXY) and can be applied to data points symbol and/or the line segments before or after each data point (TColorEachMode = (ceNone, cePoint, ceLineBefore, ceLineAfter, cePointAndLineBefore, cePointAndLineAfter).

See the demo in the TAChart demo folder (lazarus/components/tachart/demo/line)

it's perfect

how can i do that?
You must install the trunk version of Lazarus (this is the developer version). The easiest way is using the fpcupdeluxe program (https://github.com/newpascal/fpcupdeluxe/releases/tag/v1.6.0n).
« Last Edit: February 11, 2018, 12:12:33 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus