Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-10

TAChart question

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

José Mejuto

Hello Lazarus-List,

I need to create a chart like:

5 *
4
3 *
2 *
1 *
ONE TWO THREE FOUR

My source data is a database with 2 fields:

X = string
Y = integer

How can I create this with TAChart ? It only allows me numerical values in both coordinates, or I was unable to find how to indicate that X axis is "autoincrement".

Thank you.

Best regards, Jos?

Reply by email

Alexander Klenin
to José Mejuto
Jos? Mejuto wrote 20 lines
Hello Lazarus-List, I need to create a chart like: 5 ? ? ? ? ? ?* 4 3 ? ? ? ? ? ? ? ? * 2 ? ? ? * 1 ?* ?ONE ?TWO THREE FOUR My source data is a database with 2 fields: X = string Y = integer How can I create this with TAChart ? It only allows me numerical values in both coordinates, or I was unable to find how to indicate that X axis is "autoincrement".

You should set BottomAxis.Marks.Source property to an appropriate chart data source.

See demo/axis for an example.

Alexander S. Klenin

Reply by email

José Mejuto
to Alexander Klenin

Hello Lazarus-List,

you wrote
> How can I create this with TAChart ? It only allows me numerical > values in both coordinates, or I was unable to find how to indicate > that X axis is "autoincrement".

AK> You should set BottomAxis.Marks.Source property to an appropriate AK> chart data source.
AK> See demo/axis for an example.

I had already pointed it, but the axis demo is not what I want because in axis demo the data is:

DataPoints.Strings = (
'1|18000|?|January'
'2|35000|?|February'
'3|31000|?|March'
'4|26000|?|April'
'5|37000|?|May'
'6|22000|?|June'

And I can only generate something like:

DataPoints.Strings = (
'January|18000|?|January'
'February|35000|?|February'
'March|31000|?|March'
'April|26000|?|April'
'May|37000|?|May'
'June|22000|?|June'

This means I do not have a "record index" value and to generate it I must create a temporal "memds" or alike and populate it manually which seems to be a not very usefull way.

I think I can easily patch TAChart for my needs using in TADbSource:

------------
  if FieldX  '' then
    FCurItem.X := ds.FieldByName(FieldX).AsFloat
   else
    FCurItem.X := ds.recno;
------------

But I do not like to modify standard components. Thank you.

Best regards, Jos?

Reply by email

José Mejuto

Hello Alexander,

you wrote
> ?DataPoints.Strings = ( > ? ?'January|18000|?|January' > ? ?'June|22000|?|June'

AK> As a separate note, I'd like to point out that using DataPoints property AK> in not an efficient way to fill the > Use ListChartSource.Add instead. AK> This property is primarily intended to allow design-time editing, AK> mostly for demonstration purposes.

I had used just here only to show my data structure in the "natural" format at design time ;)

> But I do not like to modify standard components. Thank you.

AK> Do you use ListChartSource or DbChartSource as a primary source for AK> your data? If first, then you can easily generate "index" for X values AK> like this:
AK> for i := 1 to NumPoints do
AK> ListSource.Add(i, YValue[i], 'text label', clTAChart);

I'm using DbChartSource (which present many stability bugs) and I whish to stay, as much as possible, away from coding to generate the charts.

AK> If, however, your data comes directly from the database via DbChartSource, AK> then I believe you are right, lack of record index may be inconvenient. AK> Btw, how do you display the series itself? It should suffer from the AK> exact same problem.

I'm a bit lost with the terminology of the chart. I'm using a bar series with the above "patch" and the only problem is that axis text are a "mess" because if I allow them to overlay it is impossible to read most of them, if hide neightbor only some of them can be read, and in this case the legend can not be used as all data points share the same "color". It would be great, at least for bar series, to be possible to generate something like this (using countries):

100%| * * United States Of America 100% | * # @ Portugal 50%
50%| * @ # # Italy 75%
| * @ #
0%| * @ #
--------------
USA POR ITA

So the axis text is different than the legend text. I'm using something like this and my database data is:

COUNTRY3C 3 char
COUNTRYNAME VARCHAR
PERCENT Float

In SQL is quite difficult to return a row number to act as an index.

Also for the BottomAxis at least I whish to suggest a new mode to write, so using Ignore, Hide neightbor and the new one, "scattered" or "intercaled" or "shuffled". Something like:

100%| *
| * #
50%| * @ #
| * @ # $
0%| * @ # $
-----------------
USA ITA
POR OTHER

Which will double the possibilities of display complete texts.

AK> Anyway, I think your idea to return record index in case of
AK> empty FieldX makes a lot of sense, so I applied your patch in r27551

Thank you, but maybe it would be better to use a "faked" field name like:

if FieldX=':recno' then
  FCurItem.X := ds.RecNo;
else if FieldX=':reccount' then
  FCurItem.X := ds.RecCount;

This is just a possibility for future expansions, anyway using empty field to a default to recno looks fine to me.

I'll try to take a look at a bug that is bringing down the IDE when in a connected data source to a chart you write a wrong field name and press enter, the sucession of access violations bring down the IDE (Windows/32 at least).

Best regards, Jos?

Reply by email