TLineSeries show every n'th pointer lazarus / 55-TAChart ---------------------------------------------------------------------- mtanner · 2016-02-17 16:58 Is it possible to plot a TLineSeries with only a subset of the pointers plotted? What I'm describing is an option that exists in Latex/PgfPlots where every point is plotted, so as to get the most accurate shape, but not every point has a pointer. This would be useful where the pointers are too close togetehr. I realise a workaround would be to skip some points in the plotting code. Could also use separate series for the line and the points, though that gives problems with the legend. ---------------------------------------------------------------------- wp · 2016-02-17 20:17 Quote from: mtanner on February 17, 2016, 05:58:28 pmIs it possible to plot a TLineSeries with only a subset of the pointers plotted? There is not built-in function or property for that. But it is not difficult to achieve this: The basic idea is that you don't store the data inside the series by calling its AddXY, but use a separate chartsource to provide the data points - this gives you more freedom in data selection without adding multiple storage. One reasonable scenario, for example, is that your data primarily come in as an array of - say - TDataPoint records: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TDataPoint = type    x, y: Double;  end;   TDataPointArray = array of TDataPoint; var  data: TDataPointArray; Then you could use a TUserDefinedChartSource to pass this array to the series by defining the count of datapoints in the source's PointsNumber property and by writing an event handler for OnGetChartDataItem: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UserDefinedChartSource1.PointsNumber := Length(data);   // somewhere when data arrive... procedure TForm1.UserdefinedChartSource1GetChartDataItem(ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);begin  AItem.X := data[AIndex].x;  AItem.Y := data[AIndex].y;end;  This code plots every data point. In order to plot every - say - 10th datapoint you divide the Pointsnumber by 10 and multiply the index of the ChartSource by 10. In this combination only every 10th data point is passed to the chart. The code would be something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   UserDefinedChartSource1.PointsNumber := Length(data) div 10;...  procedure TForm1.UserdefinedChartSource1GetChartDataItem(ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);  begin    AItem.X := data[AIndex*10].X;    AItem.Y := data[AIndex*10].Y;  end; QuoteCould also use separate series for the line and the points, though that gives problems with the legend.You can exclude a series from being listed in the legend by setting its Legend.Visible to false. ---------------------------------------------------------------------- mtanner · 2016-03-11 14:53 Thanke for the suggestion, though it does not feally address my question.I have come up with a solution which works fine, though not elegant. Instead of a sinle TLineSeries, I use 3 TLineSeries, lets call them SerLine, SerPnts, and SerLgnd. Serline does not have any pointers, just the line, and has all the data points. For the applications I'm dealing with the curves can have very sharp bends, and may be asymptotic to the y-axia. This happens a lot in scientific or statitical applications, but not very often in business applications. So a high density of data points may be needed to display the shape of the curve properly. SerPnts has points but no line, and includes every n'th point, which stops the points crowding together untidily. Neither SerLine or SerPnts is included in the legend. The third series SerLgnd has both points and line, but actually has no data points, but is used to create the correct appearance in the legend. This solution works quite well. The number of data points is not massive, so the duplication of lines is not a problem.  I would like to submit as a suggestion for future development another parameter on the TLineSeries, say PointFrequency, to allow only every n'th point to be plotted. I can't see that this would be particularly complicated and it would be useful. Latex/PgfPlots has such a parameter. ---------------------------------------------------------------------- wp · 2016-03-11 16:11 Quote from: mtanner on March 11, 2016, 03:53:35 pmthough it does not feally address my question...the curves can have very sharp bends, and may be asymptotic to the y-axia. This happens a lot in scientific or statitical applications... I would like to submit as a suggestion for future development another parameter on the TLineSeries, say PointFrequency, to allow only every n'th point to be plotted. I can't see that this would be particularly complicated and it would be useful. Latex/PgfPlots has such a parameter. You did not say that you want a variable point density, you were only talking of omitting the pointers of specific data points. The real solution to your issue is to use points at not-equidistant x values. With non-equidistant x you can draw very steep, vertical  or even backward edges. ---------------------------------------------------------------------- mtanner · 2016-03-14 12:14 Sorry if my explanation was not clear. I am actually using non- equidistant x-values, but I still need to only show every n'th value as, since the point density around a function singularity needs to be high to get the correct shape, but this would  cause the pointers to crowd together. ---------------------------------------------------------------------- wp · 2016-03-14 16:03 No, don't you understand? A "show every nth value" feature will dilute the data points uniformly all over the chart. Once you tuned the n such that the densitiy is correct at steep parts of the curve the density will be too low at flat parts. You need variable x spacings. You say that you do this already - I say: then your spacings are not correct. Ideally select the x values such that the xy distance to the previously drawn point is approximately constant. With "xy distance" I mean: sqrt(sqr(x1-x2)+sqr(y1-y2)).