Topic: Regarding Bar Chart Representation

Hi everyone,

I created a bar chart using this script example (This one: … ?id=5340), and it works. I have data for months and income. Currently, I'm using numbers instead of month names to represent the correct month. Is there any way to use strings instead of floats or dates in bar charts?

Many thanks!

ChartBar := TChart.Create(Main);
  ChartBar.Parent := Main.LevelChart;
  ChartBar.Align := alClient;


Re: Regarding Bar Chart Representation

Any comments?

Re: Regarding Bar Chart Representation

You mean getting the names of the month on the X axle  instead of the 1 to 12 ?

4 (edited by sparrow 2024-04-02 19:45:58)

Re: Regarding Bar Chart Representation

sonixax wrote:

Any comments?

In the example you indicated:
Update the ChartBar creation code part:

  ChartBar := TChart.Create(Form1);
  ChartBar.Parent := Form1.PanelBar;
  ChartBar.Align := alClient;
  ChartBar.Series[0].XValues.DateTime := true;

Update procedure Form1_bBarUpdate_OnClick

procedure Form1_bBarUpdate_OnClick (Sender: string; var Cancel: boolean);
    Results: TDataSet;
    DateValue: Double;
    QtyValue, Lab: string;

    SQLQuery('SELECT date, qty, CASE strftime(''%d'', date)*1 WHEN 1 THEN ''Jan'' WHEN 2 THEN ''Feb'' ELSE ''Other'' END AS Lab FROM bar_data ORDER BY date DESC', Results);

    while not Results.Eof do
        DateValue := SQLDateTimeToDateTime( Results.FieldByName('date').asString );
        QtyValue := Results.FieldByName('qty').asString;
        Lab := Results.FieldByName('Lab').asString;

        if ValidInt(QtyValue) then ChartBar.Series[0].AddXY(DateValue, StrToInt(QtyValue), Lab);


On the X axis we now display months as an example.

Post's attachments

Attachment icon ex.jpg 32.84 kb, 2 downloads since 2024-04-02 

Re: Regarding Bar Chart Representation

You can also use this form for the Sql Query with sqlite:

 SQLQuery('select substr('JanFebMarAprMayJunJulAugSepOctNovDec', 1 + 3*strftime('%m', date), -3) AS Lab FROM bar_data ORDER BY date DESC', Results)