TChart start position lazarus / 55-TAChart ---------------------------------------------------------------------- flori · 2021-02-27 08:15 Does anyone know where is the EndPosition, StartPosition on my TChart? I have just position. https://wiki.lazarus.freepascal.org/Comparing_TAChart_with_Delphi's_Te eChart_Standard ( it doesn't look like that to me) ---------------------------------------------------------------------- wp · 2021-02-27 12:26 I don't understand what you want to say. ---------------------------------------------------------------------- flori · 2021-02-27 13:39 I found it. Extend: Ymax, Ymin /Xmax Xmin -start y/start x WP> I create a small demo which use dbf. ->ID, FARM_Name, YIELD. I want to display these TChart BarSeries. As a result I get different column size(I do not understand why!) Small demo project with different behavior of TChart. When I change Id: 1,2,3.. then I get good results. I attached small demo. Thanks for watching ---------------------------------------------------------------------- flori · 2021-02-27 14:07 I think my Lazarus Chart is not working good. I try listChartsource : as a results: different column width X   y 1   25 2   26 4   27 When I modified: as a results: same column width x   y 1   25 2   26 3   27 it's OK ---------------------------------------------------------------------- flori · 2021-02-27 14:32 I create small demo2 with TChartListSource. The TChart column is different width. I do not understand ---------------------------------------------------------------------- wp · 2021-02-27 15:38 I could not run your demo because I do not use your report engine. (Please try to keep demos as simple as possible). But I could see in the lfm file that the x values of the bar series are not equidistant: 2001, 2002, 2003, 2006. In its default settings, the BarSeries calculates the bar widths on the basis of BarWidthPercent in which the "percent" refers to the distance to the next (or previous?) data point. So, when the x values do not have the same distance the bars will vary in width. To adjust the bars to equal widths you must set the BarWidthStyle to bwPercentMin which looks for the smallest x value distance and calculates the widths of all bars based on this value. Alternatively to changing the BarWidthStyle you can also add "empty" values at the missing years, 2004 and 2005: 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   ListChartSourc1.Add(2001, 2, 'Farm1');  ListChartSource1.Add(2002, 50, 'Farm2');  ListChartSource1.Add(2003, 9, 'Farm4');  ListChartSource1.Add(2004, NaN);   // <--------- This is a "missing" value  ListChartSource1.Add(2005, NaN);  ListChartSource1.Add(2006, 50, 'Farm3');You must add unit math to the uses clauses to get access to NaN ("not a number"). ---------------------------------------------------------------------- flori · 2021-02-27 17:34 WP> Thank you very much for your help!  I create a small demo again. I just set ListChartSource. Unfortunately, users (farmers) change the years many times. Never contain such as: 2012,2013, 2014. Usually the years is unsettled. (2008, 1988, 1999, etc) they are not sorted by year. I set BarWidthStyle to bwPercentMin and x values of the bar series are equal. The column width is ok , but unfortunately the distance between columns are not equal. (not user friendly and does not looks good). Thanks ---------------------------------------------------------------------- flori · 2021-02-28 07:26 Quote from: flori on February 27, 2021, 06:34:27 pmWP> Thank you very much for your help!  I create a small demo again. I just set ListChartSource. Unfortunately, users (farmers) change the years many times. Never contain such as: 2012,2013, 2014. Usually the years is unsettled. (2008, 1988, 1999, etc) they are not sorted by year. I set BarWidthStyle to bwPercentMin and x values of the bar series are equal. The column width is ok , but unfortunately the distance between columns are not equal. (not user friendly and does not looks good). Thanks Does anyone know how to solve this problem? Many thank u!! ---------------------------------------------------------------------- flori · 2021-02-28 08:00 Quote from: wp on February 27, 2021, 04:38:03 pmI could not run your demo because I do not use your report engine. (Please try to keep demos as simple as possible). But I could see in the lfm file that the x values of the bar series are not equidistant: 2001, 2002, 2003, 2006. In its default settings, the BarSeries calculates the bar widths on the basis of BarWidthPercent in which the "percent" refers to the distance to the next (or previous?) data point. So, when the x values do not have the same distance the bars will vary in width. To adjust the bars to equal widths you must set the BarWidthStyle to bwPercentMin which looks for the smallest x value distance and calculates the widths of all bars based on this value. Alternatively to changing the BarWidthStyle you can also add "empty" values at the missing years, 2004 and 2005: 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   ListChartSourc1.Add(2001, 2, 'Farm1');  ListChartSource1.Add(2002, 50, 'Farm2');  ListChartSource1.Add(2003, 9, 'Farm4');  ListChartSource1.Add(2004, NaN);   // <--------- This is a "missing" value  ListChartSource1.Add(2005, NaN);  ListChartSource1.Add(2006, 50, 'Farm3');You must add unit math to the uses clauses to get access to NaN ("not a number"). I try different years: The column width is ok , but unfortunately the distance between columns are not equal. 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  ListChartSource1.Add(2001, 2, 'Farm1');  ListChartSource1.Add(2002, 50, 'Farm2');  ListChartSource1.Add(2003, 9, 'Farm4'); // ListChartSource1.Add(2004, 0);   // <--------- This is a "missing" value  //ListChartSource1.Add(2005, 0);  ListChartSource1.Add(2006, 50, 'Farm3'); ---------------------------------------------------------------------- bpranoto · 2021-02-28 08:21 I would make the labels plain consecutive integer value: 0,1,2,3...etc Then I create an array to map those values to the year: 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  TDynIntArray = array of Integer; constructor TForm1.Create(AOwner: TComponent);   procedure AAdd( var AArray: TDynIntArray ; Value:Integer );  var    i : Integer;  begin    SetLength(  AArray,Length(AArray) + 1 );    i := Length(AArray);    AArray[i-1] := Value;  end; begin  inherited Create(AOwner);  AAdd(Self.FMapXYear,2012);  AAdd(Self.FMapXYear,2013);  AAdd(Self.FMapXYear,2019);  AAdd(Self.FMapXYear,2021);end;  After that, I set the bottom TChartAxis onMarkToText event to print the year instead of the x value: 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 procedure TForm1.Chart1AxisList1MarkToText(var AText: String; AMark: Double);var  i : Integer;begin  i := StrToInt( AText);  if i >= 0 then begin    AText := IntToStr(Self.FMapXYear[i]);  end;end;  Attached is the screenshot ---------------------------------------------------------------------- flori · 2021-02-28 08:53 Quote from: bpranoto on February 28, 2021, 09:21:31 amI would make the labels plain consecutive integer value: 0,1,2,3...etc Then I create an array to map those values to the year: 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  TDynIntArray = array of Integer; constructor TForm1.Create(AOwner: TComponent);   procedure AAdd( var AArray: TDynIntArray ; Value:Integer );  var    i : Integer;  begin    SetLength(  AArray,Length(AArray) + 1 );    i := Length(AArray);    AArray[i-1] := Value;  end; begin  inherited Create(AOwner);  AAdd(Self.FMapXYear,2012);  AAdd(Self.FMapXYear,2013);  AAdd(Self.FMapXYear,2019);  AAdd(Self.FMapXYear,2021);end;  After that, I set the bottom TChartAxis onMarkToText event to print the year instead of the x value: 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 procedure TForm1.Chart1AxisList1MarkToText(var AText: String; AMark: Double);var  i : Integer;begin  i := StrToInt( AText);  if i >= 0 then begin    AText := IntToStr(Self.FMapXYear[i]);  end;end;  Attached is the screenshot Thanks. But How can I solve this problem when I use dbf? I attached small demo. Because the years change often. (1999, 2005, 2009, etc) ---------------------------------------------------------------------- flori · 2021-02-28 09:03 unfortunately it doesn't work with DBF or other DB (ZQUery, etc) ---------------------------------------------------------------------- bpranoto · 2021-02-28 10:05 Quote from: flori on February 28, 2021, 09:53:04 amThanks. But How can I solve this problem when I use dbf? I attached small demo. Because the years change often. (1999, 2005, 2009, etc) Unfortunately, I can't load your project because I don't have the report component that you used. The idea is what you put into the data is a simple continous integer, then you control what is to be shown in onMarkToText event. ---------------------------------------------------------------------- bpranoto · 2021-02-28 10:42 I succesfully managed to compile your sample project. Here what I modified: 1. Add a field XLABEL to farm.dbf, fill the record with 1,2 2. Change the property FieldX of DBChartSource1 to XLabel 3. Create onMarkText event: 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 procedure TForm1.Chart2AxisList1MarkToText(var AText: String; AMark: Double);var  XVal:Integer;begin  XVal := StrToInt(AText);  Dbf1.Locate('XLABEL',XvAL,[]);  AText := Dbf1.FieldByName('ID').AsString;end;  The modified project is attached ---------------------------------------------------------------------- flori · 2021-02-28 11:10 Quote from: bpranoto on February 28, 2021, 11:42:19 amI succesfully managed to compile your sample project. Here what I modified: 1. Add a field XLABEL to farm.dbf, fill the record with 1,2 2. Change the property FieldX of DBChartSource1 to XLabel 3. Create onMarkText event: 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 procedure TForm1.Chart2AxisList1MarkToText(var AText: String; AMark: Double);var  XVal:Integer;begin  XVal := StrToInt(AText);  Dbf1.Locate('XLABEL',XvAL,[]);  AText := Dbf1.FieldByName('ID').AsString;end;  The modified project is attached Thank you. It works with just 2 rows. While I add to 3 rows doesn't work.  (ID(2012)...+ID (i)) ---------------------------------------------------------------------- wp · 2021-02-28 11:15 See the attached modified demo with the dbf file. The problem is that you essentially need two x values - one for the labels (years), and one for plotting, and the latter ones must be equidistant. If you'd use TAChart of Lazarus trunk you'd have the possibility to use multiple x values. But in the release version - which I am assuming in the demo project - this is not possible. However, you can extend the Text field of the data point record by the year values: 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   Chart1ListSource1.Item[datapoint_index]^.Text := Format('%s|%g', [    Chart1ListSource1.Item[datapoint_index]^.Text,    Chart1ListSource1.Item[datapoint_index]^.X ]); As you can see this adds the x value as a string the the original farm name, separated by a pipe character ('|'). Then for drawing the axis labels you must extract the year string from the combined Text field by finding the separator character and copying the text afterwards. This happens in the OnGetMarkText event of the x axis (or the OnMarkToText event) The same is needed for the series labels - if you want to display them - by picking the text before the pipe character. This is the responsibility of the OnGerMark event of the series. Since your data are not entered in an ordered fashion you must sort them. You can either sort the data set (which is preferred because it will also sort the DBGrid), or you can sort the ListChartSource (ListChartSource.Sorted := true). When the data is sorted you iterate through the dataset and populate the ListSource. I avoid the DBChartSource at all because it turned out that it does not report the RecordCount correctly - which would show many empty bars in the chart... After (or during) population of the ListChartSource the Text field is extended as explained above, and the X field is set to the running index to make it equidistant. I think I should note that it is important to enclose the population steps of the ListChartSource by a BeginUpdate/EndUpdate block because otherwise the extent of the axis wil not be up-to-date. I hope this description is clear enough so that you understand the principle. Study the code provided. Otherwise ask again. ---------------------------------------------------------------------- bpranoto · 2021-02-28 11:20 Quote from: flori on February 28, 2021, 12:10:43 pmThank you. It works with just 2 rows. While I add to 3 rows doesn't work.  (ID(2012)...+ID (i)) You have to manually set the content of the field XLABEL for every record. Modify the grid to also shows the XLABEL field.... ---------------------------------------------------------------------- bpranoto · 2021-02-28 11:21 and make sure the records are sorted by XLABEL.... ---------------------------------------------------------------------- bpranoto · 2021-02-28 11:29 Here is the modified version: ---------------------------------------------------------------------- flori · 2021-02-28 12:09 WP and bpranoto thank you for your help I am trying to implement the codes in FastReport (tfrxReport). MANY THANK YOU! ---------------------------------------------------------------------- bpranoto · 2021-02-28 12:30 You're welcome!