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
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:You must add unit math to the uses clauses to get access to NaN ("not a number").
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');
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:
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:
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)
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:
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))