Recent

Author Topic: [SOLVED] Negative Bars in TBarChart?  (Read 4913 times)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
[SOLVED] Negative Bars in TBarChart?
« on: May 12, 2012, 12:13:52 pm »
What are the required steps to allow drawing of negative bars in TBarChart?

If I write (using the barchart example that comes with Lazarus)

Code: [Select]
  BarChart1.AddBar('1999',200,clGreen);
  BarChart1.AddBar('2000',-300,clred);
  BarChart1.AddBar('2001',300,clred);
  BarChart1.AddBar('2003',400,clGreen);
  BarChart1.AddBar('2004',400,clGreen);

the negative bar at 2000 is clipped at the left margin of the plot.

What do I have to do that the plot scales to draw all bars?
« Last Edit: May 12, 2012, 02:28:39 pm by jwdietrich »
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Negative Bars in TBarChart?
« Reply #1 on: May 12, 2012, 01:29:08 pm »
TBarChart is deprecated. You can try using TAChart instead.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Negative Bars in TBarChart?
« Reply #2 on: May 12, 2012, 01:43:56 pm »
Thanks for the hint, I didn't know that. I will give TAChart a try.

If TBarChart is deprecated it might be an idea to remove the demo that is bundled with Lazarus.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Negative Bars in TBarChart?
« Reply #3 on: May 12, 2012, 02:20:59 pm »
... 5th link from the top in the list with links top leftt...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Negative Bars in TBarChart?
« Reply #4 on: May 12, 2012, 02:27:59 pm »
Thanks again for the hints. The solution is quite easy.

The steps are:

1. Create a TChart in the form
2. Create a TBarSeries in the Chart
3. Add

Code: [Select]
BarSeries.AxisIndexX := 1;
BarSeries.AxisIndexY := 0;

4. Use the rotate procedure from the rotate demo of the TAChart component.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Negative Bars in TBarChart?
« Reply #5 on: May 12, 2012, 02:31:00 pm »
... 5th link from the top in the list with links top leftt...

OK, I will even go an additional step and modify the demo application, so that it is based on TAChart. But I will not manage to do this today.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [SOLVED] Negative Bars in TBarChart?
« Reply #6 on: May 12, 2012, 02:39:16 pm »
Thanks a lot!
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Negative Bars in TBarChart?
« Reply #7 on: May 12, 2012, 07:09:20 pm »
4. Use the rotate procedure from the rotate demo of the TAChart component.

Note that this step is required only if you want to allow user to rotate the chart.
If you just want the horizontal bars, setting AxisIndexX = 0, AxisIndexY = 1 is enough.

 

TinyPortal © 2005-2018