Topic: Refresh a chart

Hello Dmitry

I'm using chart on a form in a project. All works fine !
In this project I've added a fonction import (from csv)
I also can exporte to csv, txt and html

I'm wondering how to refresh this chart along the data contained in a new file.
(i.e on opening application, the grid displays eight rows and the chart shows eigth points on the graph).

Then i import a new file (csv) with five rows and the chart displays always eight points.

To refresh, I use this code

procedure Form1_Button6_OnClick (Sender: string; var Cancel: boolean); //  Bouton Rafraîchir
var Results   : TDataSet;
    DateValue : Double;
    TauxValue : String;
begin
    ChartLine.Series[0].Clear;

    SQLQuery('SELECT Date_Prise, Taux FROM diabete ORDER BY Date_Prise DESC', Results);

    while not Results.Eof do
    begin
        DateValue  := SQLDateTimeToDateTime( Results.FieldByName('Date_Prise').asString );
        TauxValue  := Results.FieldByName('taux').asString;
        if ValidFloat(TauxValue) then ChartLine.Series[0].AddXY(DateValue, StrToFloat(TauxValue));
        Results.Next;
    end;
end;

Does this procedure allows to refresh datas of the new file imported (csv) ?

For those using Chartline, you can deactivate 3D view with this instruction :

If not Form1.CheckBox1.Checked then
      ChartLine.View3D := False (or  False)

You also can deactivate display of legends with this instruction :

If not Form1.CheckBox2.Checked then
      ChartLine.Legend.Visible := True  (of False);

Thanks Dmitry for your answer.

JB

Re: Refresh a chart

Hello,


You want display on chart only new data from new imported file?

Dmitry.

Re: Refresh a chart

Hello Dmitry

Yes, it is only what I want : display a chart for only new data from imported file

Thanks

JB

Re: Refresh a chart

jean.brezhonek wrote:

Hello Dmitry

Yes, it is only what I want : display a chart for only new data from imported file

Thanks

JB

Hello,


You should create a new database field, where you can store date and time (or just unique number) for the imported data, thus you can separate one import from another one. After that just add this field to the WHERE section of sql query for the chart.

Dmitry.

Re: Refresh a chart

Hello Dmitry

Thank for your answer.

In fact I had thought to create a new field in the database, as you suggest it,
But the exact syntax was not coming with operator WHERE.

When you say unique number, do you mean id of the record ?
How tcan I create a field with two values : date and time ?

Thank for your answer

JB

Re: Refresh a chart

jean.brezhonek wrote:

Hello Dmitry

Thank for your answer.

In fact I had thought to create a new field in the database, as you suggest it,
But the exact syntax was not coming with operator WHERE.

When you say unique number, do you mean id of the record ?
How tcan I create a field with two values : date and time ?

Thank for your answer

JB


Create a field with type INTEGER.
Before you start import, create a variable with random value

var
    iRnd: integer;
begin
    iRnd := Trunc(Random*999999999);

Then insert this random value for every imported record.

SQLExecute ('INSERT INTO tablename (date, value, RndNumber) VALUES ('+ sDate +','+ sValue +','+IntToStr(iRnd) +');');


Use this random value to get latest portion of imported data

SQLQuery('SELECT Date_Prise, Taux FROM diabete ORDER BY Date_Prise DESC WHERE RndNumber='+IntToStr(iRnd), Results);
Dmitry.

Re: Refresh a chart

Hello Dmitry

Original idea to use a variable with random value.
I test it  !

Any idea when implementing a TreeView (or a DBTreeView) into MVD ?

Thanks for your help

JB

Re: Refresh a chart

jean.brezhonek wrote:

Hello Dmitry

Original idea to use a variable with random value.
I test it  !

Any idea when implementing a TreeView (or a DBTreeView) into MVD ?

Thanks for your help

JB

No, in the moment work on possibility to add/edit record in a grid without form.

Dmitry.

Re: Refresh a chart

Hello Jean and Dmitry,


If you don't want to modify the database and... :


1- if you known for sure how many records you'll have to import
you could do a query to select limited n elements from a subquery in reversed order like :

SELECT * FROM (select * from table order by id DESC) LIMIT 8

2- if the number of records depends on the CSV you import :
do the same query but with a LIMIT n based on the rowcount of your CSV

SELECT * FROM (select * from table order by id DESC) LIMIT '+row_count+'

Cheers



Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Refresh a chart

Hello Dmitry

I applied your method to refresh the chart of an imported file.
But I have an error message: Near "," syntax error.
I have created a new field (Integer) as recommended.
But I think I have badly written my script or forgotten two values to successfully update the chart according to the new imported file.
Could you take a look at me and tell me what's wrong ?
thanks in advance

JB

Post's attachments

Attachment icon DIAB.zip 111.74 kb, 459 downloads since 2016-11-15 

Re: Refresh a chart

jean.brezhonek wrote:

Hello Dmitry

I applied your method to refresh the chart of an imported file.
But I have an error message: Near "," syntax error.
I have created a new field (Integer) as recommended.
But I think I have badly written my script or forgotten two values to successfully update the chart according to the new imported file.
Could you take a look at me and tell me what's wrong ?
thanks in advance

JB

You found simples way how to marks latest import data (using field is_Last_Import with default value)
I fixed some mistakes

Post's attachments

Attachment icon DIAB_fixed.zip 78.15 kb, 527 downloads since 2016-11-16 

Dmitry.

Re: Refresh a chart

Hi,

As I am interested in charting data with MVD, I had a try at the DIAB fixed project but when compiling with MVD 6.5, I get an Access violation at address 00E3CEF0 in module "Diabetes.exe".

Script position 303:8 that is:   

 If Form1.CheckBox1.Checked then
       ChartLine.View3D := True;   

Did you get it working Jean?

Re: Refresh a chart

Any component in MVD can be created in the graphical shell or dynamically while the program is running. When created, a component has mandatory properties: class, name, dimensions... events... etc. .  Some properties can be changed dynamically while the program is running. But any access to the component and changing its properties is possible only after its creation. Otherwise it causes an error.
But overall the program is working.

Re: Refresh a chart

sparrow wrote:

But overall the program is working.

Which version of MVD are you using, I did not modify the project, I just want first to see how it works and it does not even start, it trows away the access violation error.