|
problem with missing values |
Posted by cc on Apr-29-2011 15:15 |
|
hi,
ive got a problem with missing values here...
usually, i get all data from a database, like
time | value
2011-01-01 23:00:56 | 456
2011-01-01 23:00:57 | 123
2011-01-01 23:00:58 | 789
... and so on.
but i now use different tables for different graphs.
and it may happen, that table 1 starts at
2011-01-01 00:00:56
and ends at
2011-01-01 23:59:56
and table 2 starts at
2011-04-04 23:00:56
and ends at
2011-04-04 23:20:56
now the problem is, that the chart 2, that starts later has less values than table 1, so the data from table 2 is "moved to the left".
i am using the perl version.
is it possible to do something like a hash, like
my %hash = ( '123456787' => 545, '123456788' => 568, ...) [when 123456... is unix time]?
or is it possible to avoid to move it to the left? |
Re: problem with missing values |
Posted by Peter Kwan on Apr-30-2011 00:23 |
|
Hi cc,
If you have a chart, and the data are from 2011-04-04 23:00:56 to 2011-04-04 23:20:56, by default, ChartDirector will create an axis that is also from the same or similar time range. So the first data point in the chart at or near the starting point of the axis.
ChartDirector will not automatically create an axis that is using a different time range. For example, it will not start the axis at the year 2000-01-01 00:00:00, or 2011-04-04 00:00:00 or any other arbitrary time. (It does not matter if you are using a "hash" or not.)
If you would like the axis to start in a certain specific time, you may use the ChartDirector API to configure the axis scale. There are several methods. For a line chart, a common method is to use Axis.setDateScale to set the axis range, and then use Layer.setXData to tell ChartDirector where are the x-coordinates of the data points.
See the sample code "Uneven Data Points" for an example of using setXData. In this sample code, note that the orange line does not start from the left, but from somewhere in the middle of the chart. This may be what you want.
To set the axis scale, the code is like:
$c->xAxis()->setDateScale(perlchartdir::chartTime(2011, 4, 4, 0, 0, 0), perlchartdir::chartTime(2011, 4, 5, 0, 0, 0));
Note the ChartDirector does not use UNIX timestamps to represent date/time. If you are using UNIX timestamps, you may use perlchartdir::chartTime2 to convert them to the ChartDirector chartTime format first, before passing the values to ChartDirector. You may look for "Date Representation" in the ChartDirector documentation index for more details.
Hope this can help.
Regards
Peter Kwan |
|