Page 1 of 1

A chart with 3 series?

Posted: Mon Mar 13, 2017 4:19 pm
by 16880166
I don't know how I can create this, but I need a chart that looks like the attachment. The top would be a bar chart with 2 series. One for income and on for Expenses by month of the year. I am building it from a SQL query when goes something like this:

Code: Select all

SELECT *, ABS(SUM (AMOUNT)) AS ABSTOTAL, 
  SUM (AMOUNT) AS TOTAL, 
  (cast(strftime('%d', date) as integer)) AS DAY,
  (cast(strftime('%d', date) as integer)) / 7 + 1 AS WEEK,
  (cast(strftime('%m', date) as integer)) AS MONTH,
  (cast(strftime('%m', date) as integer) + 2) / 3 as QTR,
  (cast(strftime('%Y', date) as integer)) AS YEAR
  FROM TRANSACTIONS
  INNER JOIN CATEGORIES
  ON TRANSACTIONS.TREE_NAME=CATEGORIES.CatName
  GROUP BY TREE_NAME
I figure for the Bar Chart I would use Total as from my Income category, and ABSTOTAL as the second series of the bar chart. This way the bars are all above the 0 line.

The 3rd series would use either total because it looks like the pie charts already use ABS amounts when they are built.

But I can figure out how to design it where the bar chart is above, and the pie chart is below. Also how to create the pie chart, so it is flat as it looks in the attachment.

Any help would be appreciated because this is my first project that I am using the Standard FMX TChart component.

Thanks.

Re: A chart with 3 series?

Posted: Tue Mar 14, 2017 10:43 am
by yeray
Hello,

Regarding the data, you should use a TSQLQuery or similar and set it to use your database. Once you have this, you should set your series to use the fields returned by the query as X values, Y values (and Labels optionally). Note the chart should be a TDBChart so the series can be set to use a DataSet as Data source.
This should be very similar to what is explained in the Tutorial 8. Database access. Find all the online Tutorials here.

Regarding the layout, I see two options:
- You can create two charts. One on the top with two TBarSeries, and one on the bottom with a TPieSeries.
- You can create a chart with a TSubChartTool. The main chart could contain the two TBarSeries and the Chart in the SubChartTool could contain the TPieSeries.

Re: A chart with 3 series?

Posted: Tue Mar 14, 2017 4:44 pm
by 16880166
Thank you for this. Right now I am still trying to code the correct query to get the charts filled. I was hoping to use one query for both charts, but that didn't seem possible due to the grouping of the queries. I am currently using 2 charts on a Tabsheet. I was hoping I could position the two charts showing the 1st chart (bar) only taking up 1/3 of the page while the pie chart takes up 2/3 of the page. But I couldn't find a setting that would give positions is %'s (I want the charts to maintain their % of the screen when the application is resized), so I ended up splitting them with a splitter. Not really what I wanted to do. Is there a setting I am missing?

I didn't know about a subchart possibility. If I choose that, could I position my charts the way I want? Is that available in the Standard version of TeeCharts FMX?

I will look at the tutorials. Hopefully, they might answer my questions about sub-charts. But for some reason, I thought they were only available in the pro version.

Last Question. Is there a way to add a scroll bar to the legend? I have seen scroll bars mentioned in the forum but don't see a setting for it. Instead, my legend just cuts off the bottom when resized.

Thanks.

Re: A chart with 3 series?

Posted: Wed Mar 15, 2017 9:52 am
by yeray
Hello,
realsol wrote:I am currently using 2 charts on a Tabsheet. I was hoping I could position the two charts showing the 1st chart (bar) only taking up 1/3 of the page while the pie chart takes up 2/3 of the page. But I couldn't find a setting that would give positions is %'s (I want the charts to maintain their % of the screen when the application is resized), so I ended up splitting them with a splitter. Not really what I wanted to do. Is there a setting I am missing?
You could set the Charts Height manually at OnResize event. Ie:

Code: Select all

var DBChart1, DBChart2: TDBChart;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DBChart1:=TDBChart.Create(Self);
  DBChart1.Parent:=Self;
  DBChart1.Align:=TAlignLayout.Top;
  DBChart2:=TDBChart.Create(Self);
  DBChart2.Parent:=Self;
  DBChart2.Align:=TAlignLayout.Client;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  DBChart1.Height:=Self.Height/3;
end;
realsol wrote:I didn't know about a subchart possibility. If I choose that, could I position my charts the way I want?
Same as above. You should do the calculations at OnResize event.
realsol wrote:Is that available in the Standard version of TeeCharts FMX?
realsol wrote:I will look at the tutorials. Hopefully, they might answer my questions about sub-charts. But for some reason, I thought they were only available in the pro version.
I'm afraid the Chart Tools are only available with the Pro version. See the feature matrix here.
realsol wrote:Last Question. Is there a way to add a scroll bar to the legend? I have seen scroll bars mentioned in the forum but don't see a setting for it. Instead, my legend just cuts off the bottom when resized.
the TLegendScrollBar is also a Chart Tool only available with the Pro version.

Re: A chart with 3 series?

Posted: Wed Mar 15, 2017 6:55 pm
by 16880166
Thanks much.

Re: A chart with 3 series?

Posted: Thu Mar 16, 2017 8:18 am
by 16880166
the TLegendScrollBar is also a Chart Tool only available with the Pro version.
Since the scrollbar is a pro version feature, is there a way to create a legend on the right that has more than 1 column in the STD version? If so, is there a way to programmatically add columns as legend items are cut off the page as the user resizes the application.

Re: A chart with 3 series?

Posted: Fri Mar 17, 2017 3:29 pm
by yeray
Hello,
realsol wrote:Since the scrollbar is a pro version feature, is there a way to create a legend on the right that has more than 1 column in the STD version? If so, is there a way to programmatically add columns as legend items are cut off the page as the user resizes the application.
I'm afraid the legend doesn't support this level of customization.

Re: A chart with 3 series?

Posted: Fri Mar 17, 2017 3:32 pm
by 16880166
Thanks for the reply. Now with us 11 hours apart, i got up at 4 am hoping you would answer some of my questions. Thank you.