Recent

Author Topic: [solved] TA Chart / BarSeries: Which setting will say "no data - no draw"?  (Read 1607 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1009
I have a chart, in which I add data by code.
The x-axes holds dates.

Which setting will make that only those dates are drawn, where there are figures for?

Please see at the screenshot, how it looks and how I want it to look.
« Last Edit: June 21, 2023, 02:24:17 pm by Nicole »

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: TA Chart / BarSeries: Which setting will say "no data - no draw"?
« Reply #1 on: June 21, 2023, 10:59:30 am »
Do not assign an x value to the series; this way you use the equidistant point index --> Use Series.Add(y) rather than Series.AddXY(x, y). Convert the date to a string and apply is as additional parameter in the Add call:
Add(y, DateToStr(date)).

In order to get the dates to the horizontal axis you additionally must assign the ChartSource used by the series to the Source property of the BottomAxis.Marks. And you must also set BottomAxis.Marks.Style to smsLabel in order to see the labels defined by the Add calls:
Code: Pascal  [Select][+][-]
  1. uses
  2.   TAChartUtils;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. begin
  6.   Chart1BarSeries1.Add(Random*1000, DateToStr(EncodeDate(2000, 1, 1)));
  7.   Chart1BarSeries1.Add(Random*1000, DateToStr(EncodeDate(2020, 1, 1)));
  8.   Chart1BarSeries1.Add(Random*1000, DateToStr(EncodeDate(2022, 1, 1)));
  9.   Chart1BarSeries1.Add(Random*1000, DateToStr(EncodeDate(2022, 6, 21)));
  10.   Chart1.BottomAxis.Marks.Source := Chart1BarSeries1.Source;
  11.   Chart1.BottomAxis.Marks.Style := smsLabel;
  12. end;

« Last Edit: June 21, 2023, 11:10:06 am by wp »

Nicole

  • Hero Member
  • *****
  • Posts: 1009
This worked at sudden, thank you so much!

 

TinyPortal © 2005-2018