Recent

Author Topic: [SOLVED] How to set text values for a point from Lineseries?  (Read 14870 times)

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[SOLVED] How to set text values for a point from Lineseries?
« on: September 18, 2012, 01:22:56 pm »
So when I add a point to a line series named ls I do:
ls.addxy(1,1,'sometext',somecolor);
So when I want to change the value of point №0 I do:
ls.setXvalue(0,5), respectfully I use ls.setYvalue(0,5) for the other axis.
I have ls.setcolor(0,somecolour) but I do not have ls.setstring.
How am I to change the string?
« Last Edit: September 21, 2012, 09:48:37 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13397
Re: How to set text values for a point from Lineseries?
« Reply #1 on: September 18, 2012, 01:59:02 pm »
I suppose you store your data in the internal ListChartSource of the LineSeries. The items in that chartsource are pointers to TChartDataItem's:

Code: [Select]
type
  TChartDataItem = object
    X, Y: Double;
    Color: TChartColor;
    Text: String;
    YList: TDoubleDynArray;
    function GetY(AIndex: Integer): Double;
    procedure SetY(AValue: Double);
    procedure MultiplyY(ACoeff: Double);
    function Point: TDoublePoint; inline;
  end;
  PChartDataItem = ^TChartDataItem;   

Therefore, in order to change the Text of an item with a given index use

Code: [Select]
  LineSeries1.ListSource.Items[AIndex]^.Text := 'something';

Maybe that's good stuff for another tutorial...

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to set text values for a point from Lineseries?
« Reply #2 on: September 18, 2012, 02:08:50 pm »
You can do that:
Code: [Select]
ls.ListSource[i]^.Text := ANewText
However, the above will not update the chart automatically,
so I have added SetText procedure in r38732.

Also, updated documentation:
http://wiki.lazarus.freepascal.org/TAChart_documentation#List_source

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to set text values for a point from Lineseries?
« Reply #3 on: September 18, 2012, 02:49:16 pm »
I am not storing the data in an internal ListChartSource.
In fact, the line series has one point only, which I use as a cursor, so I want when I move the point to change its text to show some information (x value, y value, etc).
Since ls.ListSource^.Text := ANewText won't update the chart I will wait for the new build.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13397
Re: How to set text values for a point from Lineseries?
« Reply #4 on: September 18, 2012, 03:11:35 pm »
Oh - there are special tools for this kind of application. Add a TChartToolset, assign it to the chart's ToolSet, and after doubleclicking on the TChartToolset, add one of the data point tools -- see tachart/demos/tools for an example, or http://wiki.lazarus.freepascal.org/TAChart_documentation#Data_tools.

@Ask: Is there a special reason why the TChartDataItem is declared in the old "Turbo Pascal" way as an "object" instead of a "class"?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to set text values for a point from Lineseries?
« Reply #5 on: September 18, 2012, 03:40:31 pm »
Quote from: paskal
Since ls.ListSource^.Text := ANewText won't update the chart I will wait for the new build.
A note for clarity: it will not update the chart automatically.
You can always call Chart.Invalidate yourself, it is just inconvenient.

Quote from: wp
Is there a special reason why the TChartDataItem is declared ... as an "object"
Yes, it is intended for efficient data storage, not only access.
I do have a vague idea of moving to class-based API with flyweight pattern, but this is very core API, and probably widely used, so backwards compatibility will be difficult to achieve.

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to set text values for a point from Lineseries?
« Reply #6 on: September 19, 2012, 08:06:11 am »
Oh - there are special tools for this kind of application...
That is exactly what I am using for moving the cursor. Yet I see something, which to my opinion is wrong, here is how it is written in the wiki:
Quote
Data tools are linked to specific data series via AffectedSeries property, which is a string of comma-separated series indexes. Note that indexes may change if you add or remove series.
When I was trying the tools, I started searching the tag property of the series and to use the tag in Affectedseries, but it occured, that series have no tag property (unlike the GUI controls).
Using Affectedseries with dynamically created series could cause a serious mess.
What do you think?
« Last Edit: September 19, 2012, 08:47:00 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13397
Re: How to set text values for a point from Lineseries?
« Reply #7 on: September 19, 2012, 09:01:29 am »
Quote
That is exactly what I am using for moving the cursor.
I am confused: two postings above you say that you have a one-point series as a cursor, and now you say that you apply the datapont tools. The datapoint drag tool IS the cursor, there is no need for a dummy series.

Quote
I started searching the tag property of the series
What do you need the Tag for?

The datapoint tools normally don't need the AffectedSeries property; if empty the tool works on all series. You need it when you want to restrict the tool to work only on certain series. In this case you specify the series indices in the AffectedSeries properties; if there are more series than one then you separate the numbers by commas. When you change series at run-time which lead to a different numbering then you have to update AffectedSeries to the new numbers.

I get the feeling that something goes completely wrong here. You should invest the time to strip down your project and post your charting code with random data to show us exactly what you are doing.


CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to set text values for a point from Lineseries?
« Reply #8 on: September 19, 2012, 09:57:02 am »
Quote
That is exactly what I am using for moving the cursor.
I am confused: two postings above you say that you have a one-point series as a cursor, and now you say that you apply the datapont tools. The datapoint drag tool IS the cursor, there is no need for a dummy series.
In the cases that I tested, it moves a point from a series to another place. What I need is a marker with a label on a specific place (see image attached).

Quote
I started searching the tag property of the series
What do you need the Tag for?......When you change series at run-time which lead to a different numbering then you have to update AffectedSeries to the new numbers.
Exactly that is what I think is not right. If I have a fixed property like tag, I will not need to update AffectSeries, so it will cause less problems with development.
Also, consistency and standardisations are nice things, all GUI components have a tag property, why shouldn't this one have, too?
« Last Edit: September 19, 2012, 10:21:03 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13397
Re: How to set text values for a point from Lineseries?
« Reply #9 on: September 19, 2012, 10:03:46 am »
Quote
all GUI components have a tag property, why shouldn't this one have, too?

I don't see your problem - series do have a Tag, they inherit indirectly from TComponent which has a published property Tag, there's no way to get rid of it (although it sometimes would be nice...)

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to set text values for a point from Lineseries?
« Reply #10 on: September 19, 2012, 10:12:58 am »
OOPS! I just found that Series have tags. Where have I been looking before :'(
Anyway, AffectedSeries do not take it into consideration.
« Last Edit: September 19, 2012, 10:18:30 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to set text values for a point from Lineseries?
« Reply #11 on: September 19, 2012, 11:48:15 am »
Currently, AffectedSeries property refer to the series index, i.e. sequential number starting from zero.
So if your chart has 2 line series and a bar series in that order, AffectedSeries="0,2" would make a tool affect first line series and bar series, but not second line series.

If, at runtime, you insert a new area series and move it to the beginning of the list
(which is unlikely, but possible), then the same value of AffectedSeries property would now refer to area series and the second line series.

Quote
Series have tags ... AffectedSeries do not take it into consideration.
This is actually an idea which I did consider during the tools design, however:
1) Tag property is specifically intended NOT to be used by the library, leaving it free for an application programmer. So it would be a new property, something like ToolTag
2) This solution trades a quite rare problem (possible index change due to dynamic series) for requirement to set meaningful ToolTags for all series. I decided that it is better to leave simpler API.
3) If it helps, I can easily add OnIsSeriesAffected event which would allow you to dynamically narrow down affected set (for example, by checking tags).
4) Perhaps the actual problem is that setting AffectedSeries at design-time is non-intuitive. I definitely want to implement specialized property editor for it, but do not have a good UI design for it yet. For example, I have recently implemented property editor for AxisIndexX/AxisIndexY properties, which IMO should make setting them easier.


wp

  • Hero Member
  • *****
  • Posts: 13397
Re: How to set text values for a point from Lineseries?
« Reply #12 on: September 19, 2012, 12:35:10 pm »
Quote
If, at runtime, you insert a new area series and move it to the beginning of the list
We have AddSeries and DeleteSeries, maybe there should also be a "InsertSeries(AIndex, ASeries)" to insert a series at a given position in the SeriesList

CM630

  • Hero Member
  • *****
  • Posts: 1641
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to set text values for a point from Lineseries?
« Reply #13 on: September 19, 2012, 01:30:31 pm »
I have to agree that the tag property is to global.
Other things should be a matter of wider discussion.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to set text values for a point from Lineseries?
« Reply #14 on: September 19, 2012, 03:49:52 pm »
Quote from: wp
maybe there should also be a "InsertSeries(AIndex, ASeries)"
This is extremely rare operation, so I think that the current way is sufficient:
Code: [Select]
AddSeries(Series1);
Series1.Index ;= 0;

 

TinyPortal © 2005-2018