Recent

Author Topic: Applying filter on TChart causes anomaly  (Read 5629 times)

tguns

  • New member
  • *
  • Posts: 9
Applying filter on TChart causes anomaly
« on: April 26, 2012, 02:24:31 pm »
Hey guys,

I've been trying to imlement charts into my software the past few days. I got it working with TDbChartSource, hoping that filtering a dataset would have an impact on the chart outcome. And it does, which is a great thing, but it's causing a strange little problem - adding a [0,0] value, which is quite disturbing. I will demonstrate why:

http://i50.tinypic.com/4h89ig.png

http://i47.tinypic.com/idehzo.png

A user is free to choose month in the "Winnings By Month" grid which will filter the displayed rows in "Winnings For Month" grid. Another dataset which stores chart data is filtered as well. The outcome is almost right, except for the annoying [0,0] value, which has no business being there >_>. It seems that September values are connected to October values via this [0,0] value. That's why in September chart it's connected to [29] instead of [18] (I hope I make sense).

Now this chart outcome is unacceptable, I need to get rid of the [0,0] value. The problem is definitely not in dataset, since it doesn't store any row containing [0,0] values. Do you guys know any fix to this?

Thank you.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Applying filter on TChart causes anomaly
« Reply #1 on: April 26, 2012, 05:11:59 pm »
Is your app open source?
Alternatively, can you post a small demo which reproduces the problem?

tguns

  • New member
  • *
  • Posts: 9
Re: Applying filter on TChart causes anomaly
« Reply #2 on: April 26, 2012, 07:22:59 pm »
I did a small demo to demonstrate the problem.

http://davinci.fmph.uniba.sk/~timura1/chart_demo.zip

As it seems, it's not really about creating an additional [0,0] value. The chart, when unfiltered (you can see it in this demo) is connected, naturally. But when one applies a filter, the last value of the filtered range 'wants' to connect to the next value which is not present at the time (since it's filtered). Thus, last value of September connects to [0,0], and first value of October comes from [0,0].

So what are the options here? Do I need to create separate line series for each month (I would like to avoid that), or is there way to 'break' the line into pieces by month?

Thanks.

Edit: Just select row in the left grid to apply filter on the chart.
« Last Edit: April 26, 2012, 07:29:06 pm by tguns »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Applying filter on TChart causes anomaly
« Reply #3 on: April 26, 2012, 10:02:11 pm »
RecordCount property of the dataset does not respect filter.
Unfortunately, Delphi developers declared that this will not change.

Implemented a quick-and-dirty workaround in r37040.
Now your demo display is correct. However, the chart will still
run through the whole dataset to extract filtered points.

For large datasets, it is much more efficient to use SQL for filtering.

P.S. What FPC/Lazarus verison are you using?
The demo you posted did not compile under FPC 2.6.

P.P.S. User code is not supposed do call ChartSeries.Draw directly.
(In your case, you should not even call Chart.Refresh. Chart will be notified
of changes by the dataset and refresh itself).

tguns

  • New member
  • *
  • Posts: 9
Re: Applying filter on TChart causes anomaly
« Reply #4 on: April 26, 2012, 10:24:43 pm »
RecordCount property of the dataset does not respect filter.
Unfortunately, Delphi developers declared that this will not change.

Implemented a quick-and-dirty workaround in r37040.
Now your demo display is correct. However, the chart will still
run through the whole dataset to extract filtered points.

Thank you very much, gonna test it out.

For large datasets, it is much more efficient to use SQL for filtering.

It most certainly is, but I expect to execute about 25 - 30 SQL queries (once it's all done) each time a software user switches between different user profiles. I use SQLite3, and data access costs time, thus, I need to shift some of the work to Lazarus. After all, it's just a school project, and I don't expect it to release it to public any time soon.

P.S. What FPC/Lazarus verison are you using?
The demo you posted did not compile under FPC 2.6.
I am using 2.4.2. I thought it would upgrade automaticly, when I installed latest Lazarus version. Apparently, it didn't. Gonna figure it out now.

P.P.S. User code is not supposed do call ChartSeries.Draw directly.
(In your case, you should not even call Chart.Refresh. Chart will be notified
of changes by the dataset and refresh itself).
Oh? Well when I didn't call those two, nothing happened to the chart. I'll see how it works with the lastest Laz revision.

Thank you very much for your help, Ask. Hopefully no more obstacles to come :).


 

TinyPortal © 2005-2018