Recent

Author Topic: Labels under my bars in barchart?[SOLVED]  (Read 4845 times)

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Labels under my bars in barchart?[SOLVED]
« on: February 16, 2017, 02:35:44 am »
I have a barchart with bottom labels 1 2 3 4 5 6 7 automaticly created.

How can I set labels like,  one two three  instead of 1 2 3?  :(

Thanks in advance

 
« Last Edit: February 16, 2017, 03:19:00 pm by Bob the Swede »
Rob

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Labels under my bars in barchart?
« Reply #1 on: February 16, 2017, 09:46:34 am »
Do you know the related tutorial? http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_BarSeries#Using_text_labels

The tutorial adds data via the datapoint editor. You probably add data to the series by calling the BarSeries' AddXY method. This method has an optional third parameter for data point labels:

Code: Pascal  [Select][+][-]
  1.   Chart1BarSeries1.AddXY(1, y_value1, 'one');
  2.   Chart1BarSeries1.AddXY(2, y_value2, 'two');
  3.   Chart1BarSeries1.AddXY(3, y_value3, 'three');
  4.   // etc

Then, after adding all data set the Marks.Source of the BottomAxis to the ListSource of the BarSeries (this is where your data are stored), and set Marks.Style to smsLabel (you'll have to add TAChartUtils to "uses" for the compiler to find this identifier, or set the Marks.Style in ObjectInspector):

Code: Pascal  [Select][+][-]
  1. uses
  2.   TAChartUtils, ...
  3. ...
  4.   Chart1.BottomAxis.Marks.Source := Chart1BarSeries1.ListSource;
  5.   Chart1.BottomAxis.Marks.Style := smsLabel;

Now you should see the labels instead of the x values.

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Labels under my bars in barchart?
« Reply #2 on: February 16, 2017, 01:49:39 pm »
Hi wp. I was into this solution but, I got External SIGSEGV in tacustomseries.pas
Any idea what might be wrong?
Rob

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Labels under my bars in barchart?
« Reply #3 on: February 16, 2017, 02:03:54 pm »
No idea. Did you create the series? Double-click on the chart, select "Add" and pick the series type you want to add.

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Labels under my bars in barchart?
« Reply #4 on: February 16, 2017, 02:24:15 pm »
Yes,the Barchartseries is created.

I try to set 7 string labels and the code is accepted but when in runmode I have got SIGSEGV!

for a:=1 to 7 do begin
  Chart1BarSeries1.AddXY(a,a,IntToStr(mylabels[a]));
  end;
Rob

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Labels under my bars in barchart?
« Reply #5 on: February 16, 2017, 02:41:13 pm »
Code: Pascal  [Select][+][-]
  1. for a:=1 to 7 do begin
  2.   Chart1BarSeries1.AddXY(a,a,IntToStr(mylabels[a]));
  3.   end;
My guess:
Substract 1 from a when used in your mylabels array (that runs from 0 to n).

Code: Pascal  [Select][+][-]
  1. for a:=1 to 7 do begin
  2.   Chart1BarSeries1.AddXY(a,a,IntToStr(mylabels[a-1]));
  3.   end;
Getting back into programming after 8+ years.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Labels under my bars in barchart?
« Reply #6 on: February 16, 2017, 02:56:16 pm »
Why do you create the series label from the integer array mylabels? I thought you wanted words as labels.

Code: Pascal  [Select][+][-]
  1. const
  2.   mylabels: array[1..7] of string = ('one','two', 'three', 'four', 'five', 'six', 'seven');
  3.  
  4. for a := 1 to 7 do
  5.   Chart1BarSeries1.AddXY(a, a, mylabels[a]);
« Last Edit: February 16, 2017, 04:04:37 pm by wp »

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 328
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Labels under my bars in barchart?
« Reply #7 on: February 16, 2017, 03:18:38 pm »
Many thanks wp and Girlbrush.
Now I get it.
Have a nice weekend.
/Bob
Rob

 

TinyPortal © 2005-2018