[SOLVED] How to set text values for a point from Lineseries? lazarus / 55-TAChart ---------------------------------------------------------------------- CM630 · 2012-09-18 11:22 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? ---------------------------------------------------------------------- wp · 2012-09-18 11:59 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 · 2012-09-18 12:08 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 · 2012-09-18 12:49 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. ---------------------------------------------------------------------- wp · 2012-09-18 13:11 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 · 2012-09-18 13:40 Quote from: paskalSince 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 · 2012-09-19 06:06 Quote from: wp on September 18, 2012, 03:11:35 pmOh - 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: QuoteData 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? ---------------------------------------------------------------------- wp · 2012-09-19 07:01 QuoteThat 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. QuoteI started searching the tag property of the seriesWhat 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 · 2012-09-19 07:57 Quote from: wp on September 19, 2012, 09:01:29 amQuoteThat 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 from: wp on September 19, 2012, 09:01:29 amQuoteI started searching the tag property of the seriesWhat 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? ---------------------------------------------------------------------- wp · 2012-09-19 08:03 Quoteall 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 · 2012-09-19 08:12 OOPS! I just found that Series have tags. Where have I been looking before Anyway, AffectedSeries do not take it into consideration. ---------------------------------------------------------------------- Ask · 2012-09-19 09:48 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. QuoteSeries 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 · 2012-09-19 10:35 QuoteIf, 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 · 2012-09-19 11:30 I have to agree that the tag property is to global. Other things should be a matter of wider discussion. ---------------------------------------------------------------------- Ask · 2012-09-19 13:49 Quote from: wpmaybe 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; ---------------------------------------------------------------------- wp · 2012-09-19 16:27 QuoteI have recently implemented property editor for AxisIndexX/AxisIndexY properties I saw this - it is great! QuoteThis is extremely rare operation, so I think that the current way is sufficient: Code: [Select]AddSeries(Series1); Series1.Index ;= 0; Oh - this is easy. I was not aware that the Index is writeable, and did it this way: Code: [Select]Chart1.AddSeries(Series1); Chart1.Series.List.Move(Chart1.SeriesCount-1, 0); ---------------------------------------------------------------------- CM630 · 2012-09-21 07:38 Maybe it won't hurt if I mention, that this solution seems quite confusing (maybe not intuitive or nonstandard) to me. Series1.index:= 0 seems to me like „delete series 0 and put series.index in its place", but in fact it does „increment the number of all series and put series.index in position 0“. I suppose this is the reason why @wp did not expect that the index was writeable. I if the index property of list boxes is writeable, just to find out that they do not have such a property. As far as I remember, Lazarus's functionality about arrays is quite limited, if you think (maybe inserting series is really a rare case) it might be useful, I can try to spend some time to check how situation is. ---------------------------------------------------------------------- Ask · 2012-09-21 10:39 This API does not belong to TAChart -- it is standard TCollection/TCollectionItem. Moreover, it is required for integration with form designer and object inspector. Since it is well-known to Delphi/FreePascal programmers, and quite rarely needed, I think there is no reason to duplicate it. Note btw that it applies to all collections -- for example, chart axes and tools of the toolset.