Forum > TAChart
How to Use Labeled BottomAxis
(1/1)
Manda:
Hi,
I'm new to Lazarus. Using Win32/0.9.28.3/SVN 27462/FPC 2.4.0.
I have a memo with a SQL statement and a button. When I click the button, the first column should be my X Axis, and the other columns should be all in the Y Axis.
For each query.fields.count I create a new BarSeries. Except for the X (1st column).
While not query.eof, I addXY for such serie.
When X is string: FBar.AddXY(SEQ, Y, X, Color); //SEQ is a count 1, 2, 3, ..., N
When X is double: FBar.AddXY(X, Y, '', Color);
Issue 1: I can't stack my bars. They appear all overlaied when I have multiple Y (Y1, Y2, Y3). Multibar is unavailable. I tried to use Width property for each bar, but I didn't figured out how to desloc 2nd, 3rd, ... by the same width.
Issue 2: I can't change BottomAxis marks to legend of the XY point.
BottomAxis.Marks is unavailable. Didn't found how to use the BottomAxis.MarkToText function.
FBar.Marks.Style := smsLegend show all legend under the bar, not in the X Axis.
Using Char1AxisList1MarkToText I can change X Axis texts but I didn't found how to recover all X labels from my TBarSeries.
I read and tried all tachart demos. But couldn't solve the 2 problems above. Could someone give a hint?
Thanks in advance.
Manda:
Found a solution for Issue 2.
I created a global TStrings and a global Flag. Before adding my series, I filled my StringsList with query.column1 (X) values. The flag tell me the type of X (string or double).
In Chart1AxisList1MarkToText procedure, I put the code:
--- Code: --- if (gXDouble <> 1) and (sLegenda <> nil) then begin //X is string [0, 1, ..., N]
AText := '';
if (Trunc(AMark) = AMark) and (AMark >= 0) then begin
if (sLegenda.Count > Trunc(AMark)) then AText := sLegenda[Trunc(AMark)];
end;
end;
--- End code ---
Still looking for a solution for my MultiBar series.
Ask:
--- Quote from: Manda on September 26, 2010, 06:49:28 pm ---Using Win32/0.9.28.3/SVN 27462/FPC 2.4.0.
--- End quote ---
This is quite recent SVN. It is probably 0.9.29, not 0.9.28.3
--- Quote from: Manda on September 26, 2010, 06:49:28 pm ---For each query.fields.count I create a new BarSeries. Except for the X (1st column).
While not query.eof, I addXY for such serie.
When X is string: FBar.AddXY(SEQ, Y, X, Color); //SEQ is a count 1, 2, 3, ..., N
When X is double: FBar.AddXY(X, Y, '', Color);
--- End quote ---
I am confused. Do you create a bar series for every record in the dataset?
How can X be string and double for the same query?
Or do you have several queries at once?
Did you consider using dbchartsource?
--- Quote from: Manda on September 26, 2010, 06:49:28 pm ---Issue 1: I can't stack my bars. They appear all overlaid when I have multiple Y (Y1, Y2, Y3). Multibar is unavailable. I tried to use Width property for each bar, but I didn't figured out how to desloc 2nd, 3rd, ... by the same width.
--- End quote ---
If you use multi-valued source, the (single) bar series should automatically display stacked.
See demo/multi/ for an example. If you do not have this demo, then your version
is not actually SVN trunk, and you should either update or wait for release.
If you need a clustered instead of stacked bars, then you should lower bar width
and manually offset series by increasing X value for some of them.
This may be improved -- please create a feature request in the bugtracker.
--- Quote from: Manda on September 26, 2010, 06:49:28 pm ---Issue 2: I can't change BottomAxis marks to legend of the XY point.
BottomAxis.Marks is unavailable.
--- End quote ---
This is definitely a problem, but I can neither understand nor reproduce it.
What do you mean by "unavailable"? The property does not exist at all?
Or it exists but is read-only? Or something else?
Please create and post a test project demonstrating your problem,
preferably to the bugtracker.
Speaking about the OnMarkToText event, it's disadvantage is that,
depending on chart zoom level, it may be called for any X value,
not only the values corresponding to the chart source points.
So if you want to limit X marks to source points only, you should
use Axis.Marks.Source property -- see demo/axis for an example.
Manda:
Hi Ask, thanks for answering.
Thanks for your barwidthpercent and X offset tip. I have my multibar working well now.
Ask:
Since r27570, you can use BarOffsetPercent to simplify clustered bar chart drawing
Navigation
[0] Message Index