ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to add DataTable to line chart
Posted by steven on Jan-15-2020 12:05
Hello

I want to add Date of DataTable to line chart

ex.
double[] data1 = {50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 98};

change to


for (int j = 1; j < dt.Columns.Count - 1; j++)
{
    data1.add = Datatable.row[0][j]
    data2.add = Datatable.row[1][j]
}

Thanks

  Re: How to add DataTable to line chart
Posted by Peter Kwan on Jan-15-2020 18:32
Hi Steven,

There is a DBTable utility included in ChartDirector for .NET that can accept a DataTable and returns arrays of numbers. See:

https://www.advsofteng.com/doc/cdnet.htm#DBTable.htm

For your case, it is like:

//dt = your DataTable object
DBTable t = new DBTable(dt);

double[] data1 = t.getCol(0);
double[] data2 = t.getCol(1);

Hope this can help.

Regards
Peter Kwan

  Re: How to add DataTable to line chart
Posted by steven on Jan-16-2020 11:39
Thank you~~

  Re: How to add DataTable to line chart
Posted by steven on Jan-16-2020 11:58
Attachments:
Sorry

I have another question

Uploading Titles in Pictures is the time interval of the query

I want to add time to the X axis, what should I do?

can by minute, by hour, by day


In fact, there is a time field in our data table, 1 stroke per second

Please

Thanks
chart.jpg

  Re: How to add DataTable to line chart
Posted by Peter Kwan on Jan-16-2020 16:32
Hi steven,

By "time field", I assume you refer to a column of type DateTime or DateTime2 (or similar type), and not just a text string.

In this case, you can just pass the data array as the x-coordinates of the line layer. An example is at:

https://www.advsofteng.com/doc/cdnet.htm#multiline2.htm

You can obtain your timeStamps array from the database using the code I in my last message:

double[] data = t.getCol(0);
double[] timeStamps = t.getCol(1);

You can also use:

double[] data = t.getCol(0);
DateTime[] timeStamps = t.getColAsDateTime(1);

Both of the above will work.

The line layer can be added like:

LineLayer layer = c.addLineLayer2();
layer.setLineWidth(2);

// Add data series to the line layer
layer.addDataSet(data, 0x5588cc, "Alpha");
....

layer.setXData(timeStamps);


ChartDirector will then auto-scale the x-axis to a Date/Time axis, just like it will auto-scale the y-axis to a numeric axis. (Please do not use Axis.setLabels to configure the axis, the axis will use your labels array and not auto-scaled.)

If you would like to configure the label format, you can use:

// Use the hour:minute:second format (note nn refers to minute. mm refers to month.)
c.xAxis().setDateScale3("{value|hh:nn:ss}");

If you do not configure the label format, ChartDirector will automatically determine the label format based on your actual data.

If you need further help, is it possible to provide me with the charting part of your code? I need to know how the chart is configured in your case (such as how the x-axis is set up).

Regards
Peter Kwan