Recent

Author Topic: How to Use Labeled BottomAxis  (Read 8036 times)

Manda

  • Newbie
  • Posts: 3
How to Use Labeled BottomAxis
« on: September 26, 2010, 06:49:28 pm »
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

  • Newbie
  • Posts: 3
Re: How to Use Labeled BottomAxis
« Reply #1 on: September 26, 2010, 09:18:48 pm »
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: [Select]
    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;

Still looking for a solution for my MultiBar series.


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to Use Labeled BottomAxis
« Reply #2 on: September 28, 2010, 10:18:25 pm »
Using Win32/0.9.28.3/SVN 27462/FPC 2.4.0.

This is quite recent SVN. It is probably 0.9.29, not 0.9.28.3

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);

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?

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.

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.

Issue 2: I can't change BottomAxis marks to legend of the XY point.
BottomAxis.Marks is unavailable.

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

  • Newbie
  • Posts: 3
Re: How to Use Labeled BottomAxis
« Reply #3 on: October 02, 2010, 11:52:21 pm »
Hi Ask, thanks for answering.

Thanks for your barwidthpercent and X offset tip. I have my multibar working well now.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to Use Labeled BottomAxis
« Reply #4 on: October 04, 2010, 12:46:24 pm »
Since r27570, you can use BarOffsetPercent to simplify clustered bar chart drawing

 

TinyPortal © 2005-2018