Recent

Author Topic: I need a stacked bar chart  (Read 2302 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 450
I need a stacked bar chart
« on: February 20, 2019, 02:06:49 am »
Platform:  Lazarus 1.8.4, TAChart 1.0 (came with this version of Lazarus), Windows Server 2016.
I'm a beginner with TAChart.  Can some one be so kind as to tell me how to make a stacked bar chart.  I will need minimum of 1 stack, maximum of 3 stacks.  The "range" (height) of each stack will be minimum zero, and maximum 1440.  Each stack will have many different "bar segments" in it.  The stacks may, or may not, reach the 1440 mark.  The stacks may have blank "segments" in them. If that's not possible, then I'll just add a segment that is colored the same as the background.  For starters, let's draw only one stack, and let's pretend there are 4 segments in this stack, colored Red,Green,Blue and Yellow.
If there is only 1 stack, it can occupy only one third the width of the chart.  If there are 3 stacks, they can occupy the entire chart, but with a little space between each stack.

I'll tell you what I know and you can fill in the rest:

- Place TAChart on form, align to client
- Right click, Edit series, choose TBarSeries
- (Not sure to do with Axis, totally lost)
- Place a button on the form and write it's OnClick as:

Code: Pascal  [Select][+][-]
  1.   chtBPMBarSeries1.AddXY(0, 30, 'My Label', clRed);
  2.   chtBPMBarSeries1.AddXY(0, 70, 'My Label', clGreen);
  3.   chtBPMBarSeries1.AddXY(0, 40, 'My Label', clBlue);
  4.   chtBPMBarSeries1.AddXY(0, 90, 'My Label', clYellow);
  5.  

The above code doesn't do anything.  This is where I am stuck.

Thanks in advance for any help you can provide.


wp

  • Hero Member
  • *****
  • Posts: 11830
Re: I need a stacked bar chart
« Reply #1 on: February 20, 2019, 07:18:54 am »
Did you read the tutorial? http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Stacked_BarSeries

Quote
The stacks may have blank "segments" in them. If that's not possible, then I'll just add a segment that is colored the same as the background.
Not 100% sure but you may have to switch to Laz trunk for correct handling of empty stacked bar levels. But beyond that an option with an empty segment drawn in the background color is not supported because when no y value is given for this segment then it is not clear up to which height the missing segment will reach. The only supported options are: replace missing values by zero, or skip the entire bar group.
« Last Edit: February 20, 2019, 11:21:04 am by wp »

RedOctober

  • Sr. Member
  • ****
  • Posts: 450
Re: I need a stacked bar chart
« Reply #2 on: February 20, 2019, 11:43:04 pm »
I only found the Bar series tutorial, not the Stacked Bar series that you provided the link to.
Thanks for that.  I will have a read.

 

TinyPortal © 2005-2018