Forum > TAChart

[solved] adding text notes to charts

<< < (2/4) > >>

wp:

--- Quote from: Muso on July 11, 2022, 11:51:31 pm ---I was a bit too rash. I bound the tool to Ctrl+leftclick and get the input dialog. But the mark is never displayed. it cost me about an hour to realize that one must not set the Marks style in the .lfm file. Only when I keep the .lfm file untouched and set the marks style in the OnCreate form event, it works.Maybe the DataPointHint tool sneaks in here?

--- End quote ---
Cannot imagine that this is an issue. Please post a project showing this issue. Did you "invalidate" the chart after adding a data point label?


--- Quote from: Muso on July 11, 2022, 11:51:31 pm ---Now I need a way to save the mark with my data file (a CSV file that  continuously fill whenever new data arrives). Is there a proven method I should/can use for this?

--- End quote ---
Simply add a column for the data point label after the x/y values:

--- 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 TForm1.Button1Click(Sender: TObject);var  F: TextFile;  i: Integer;begin  AssignFile(F, 'data.txt');  Rewrite(F);  for i := 0 to Chart1LineSeries1.Count-1 do    WriteLn(F, Chart1LineSeries1.XValue[i]:0:6, #9, Chart1LineSeries1.YValue[i]:0:6, #9, Chart1LineSeries1.Source[i]^.Text);  CloseFile(F);end; Or, alternatively, you could take advantage of the ListSource.DataPoints property of the TListChartSource in which the series data values are accessible as a TStrings instance so that you can save/load data in a CSV-like file by calling its SaveToFile and LoadFromFile methods (note: the field delimiter is '|', i.e. the following code cannot load the file written by the previous code):

--- 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 TForm1.Button2Click(Sender: TObject);begin  Chart1LineSeries1.ListSource.DataPoints.SaveToFile('data.txt');end; procedure TForm1.Button3Click(Sender: TObject);begin  Chart1LineSeries1.ListSource.DataPoints.LoadFromFile('data.txt');end;

Muso:

--- Quote from: wp on July 12, 2022, 10:08:24 am ---Cannot imagine that this is an issue. Please post a project showing this issue. Did you "invalidate" the chart after adding a data point label?
--- End quote ---

I spent now an hour to get an example file. But neither extending your example nor simplifying my program leads to the issue. So I have no clue why this occurs. I invalidated the Chart.
------------------

However, while trying to make an example, I got a reproducible crash when editing charts:- take the attached example- right-click in Lazarus into the chart and edit the series- delete the 4th series- now use the Menu Edit -> Undo
result: access violation
Should I open a separate thread for this?
----------------------------------

I need linebreaks in the marks text. Is this possible and if so how? I see there is an HTML font style available for marks. Can i use this and input there e.g. </br>?
--------------------------------


--- Quote from: wp on July 12, 2022, 10:08:24 am ---Simply add a column for the data point label after the x/y values:

--- End quote ---

Every few seconds I get new data. As user I later add the notes. I cannot seek in the result file around to add there marks. Later marks are deleted or changed. So I think I need a kind of separate .marks file that I can write in a separate thread. I thought maybe that there exists something.

Muso:

--- Quote from: Muso on July 12, 2022, 04:22:01 pm ---I need linebreaks in the marks text. Is this possible and if so how? I see there is an HTML font style available for marks. Can i use this and input there e.g. </br>?

--- End quote ---
OK, I found now out that I can use
--- 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";}};} ---LineEnding in the string I pass to the marks text.

wp:

--- Quote from: Muso on July 12, 2022, 04:22:01 pm ---However, while trying to make an example, I got a reproducible crash when editing charts:- take the attached example- right-click in Lazarus into the chart and edit the series- delete the 4th series- now use the Menu Edit -> Undo
result: access violation

--- End quote ---
Maybe I don't understand: "right-click in Lazarus into the chart and edit the series- delete the 4th series" refers to the designmode in Lazarus? Unfortunately I cannot reproduce the bug exactly here, because the "Undo" command is disabled in the Edit menu after this... There is a crash, however, when I press Ctrl+Backspace.

I am not sure if this is a TAChart issue at all, IIRC there are issues with the Undo function in the form designer for other controls as well.


--- Quote from: Muso on July 12, 2022, 04:22:01 pm ---I need linebreaks in the marks text. Is this possible and if so how? I see there is an HTML font style available for marks. Can i use this and input there e.g. </br>?

--- End quote ---
In this case, I'd design my own InputQuery form containing a memo rather than an edit. This way you can insert line breaks easily. You could also use the HTML mode, by activating the tfHTML TextFormat of the Marks; in this mode you can insert simple HTML tags such as <br>, or you can also switch font styles.


--- Quote from: Muso on July 12, 2022, 04:22:01 pm ---Every few seconds I get new data. As user I later add the notes. I cannot seek in the result file around to add there marks. Later marks are deleted or changed. So I think I need a kind of separate .marks file that I can write in a separate thread. I thought maybe that there exists something.

--- End quote ---
Again I don't understand. You do not have to search in the data file to add a mark - you simply click on the data point and add or edit the mark text (or erase the mark text to delete the mark).

If you have many data points it may be difficult to hit an already labeled data point again for editing or deletion of the mark - maybe this is what you mean. In this case I'd populate a string grid with the indices and mark labels of all data points having marks.

A separate marks file will make things much more complicated because the mark texts are part of the data point record:

--- 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";}};} ---type  TChartDataItem = packed record  public    X, Y: Double;    Color: TChartColor;    Text: String;    XList: TDoubleDynArray;    YList: TDoubleDynArray;    ...  end;  PChartDataItem = ^TChartDataItem;

Muso:

--- Quote from: wp on July 12, 2022, 05:05:14 pm ---Maybe I don't understand: "right-click in Lazarus into the chart and edit the series- delete the 4th series" refers to the designmode in Lazarus? Unfortunately I cannot reproduce the bug exactly here, because the "Undo" command is disabled in the Edit menu after this... There is a crash, however, when I press Ctrl+Backspace.

--- End quote ---
Hmm, here Undo is enabled and crashes, see attached.
Should I open a bugreport or is this known?


--- Quote ---In this case, I'd design my own InputQuery form containing a memo rather than an edit.
--- End quote ---
Yes, this is what I have done now.


--- Quote ---Again I don't understand. You do not have to search in the data file to add a mark - you simply click on the data point and add or edit the mark text (or erase the mark text to delete the mark).
--- End quote ---
OK, I was not clear:

* - every 2 seconds I get new data (chart is a LiveChart), it is validated, if OK, added to the graph and also saved immediately to a CSV file
* - Assume I have now 2000 data points and point 1329 gets now a mark. I need to store it.
* - later I have 5000 points and the mark is changed or deleted, then I need to update the saved markThe key feature of my program is that when the program was killed, one can reload the data and continue the measurement.
That the program is suddenly closed happens more often than I thought (Windows has issues, users thought they could pull the power plug of the PC, transfer the measurement to another room etc.) In these cases I can load the existing measurements to the chart.

I cannot save the marks to the same data file because when e.g. data point number 5000 was just written, and the user add a mark for point 1200, I must seek in the file to this position to insert there the mark.
I hope it is now more clear what I need. I think I will now write a separate file only with all marks.


--- Quote ---If you have many data points it may be difficult to hit an already labeled data point again for editing or deletion of the mark - maybe this is what you mean.
--- End quote ---
No, this works OK.



--- Quote ---A separate marks file will make things much more complicated because the mark texts are part of the data point record:
--- End quote ---
I have maybe one mark a day, so in total maybe 10 marks per measurement. I thought I can parse the .marks file and set the marks for the data points.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version