|
setDateScale vs addLineLayer |
Posted by chris on Oct-02-2012 23:17 |
|
Hi,
This is a newbie question.
I have a data set of around 5,000 points. They are each associated with a date. I'm trying to get the graph drawn with an x-axis label for a subset of the days. The dates are in the format of yyyy-mm-dd. Using perl.
.
.
.
# Use 7.5 pts Arial as the y axis label font
$c->yAxis()->setLabelStyle("", 7.5);
my $dataStart = perlchartdir::chartTime($syear, $smon, $sday);
my $dataEnd = perlchartdir::chartTime($eyear, $emon, $eday);
$c->xAxis()->setDateScale($dataStart, $dataEnd, 86400);
# Add a deep blue (0x000080) line layer to the chart
$c->addLineLayer($cic_ip,0x000080);
# Output the chart
binmode(STDOUT);
print "Content-type: image/png\\n\\n";
print $c->makeChart2($perlchartdir::PNG);
If this code runs, I get a graph with a perfect x-axis, a perfect y-axis, but no graph line. If I comment out the line with "setDateScale" I get a perfect graph line and y-axis, but obviously no x-axis labels. I must be missing something obvious. Help? |
Re: setDateScale vs addLineLayer |
Posted by Peter Kwan on Oct-03-2012 00:44 |
|
Hi chris,
If you specify the x-axis scale, you must also specify the x-coordinates of the data points. ChartDirector will not assume the data points are spreading evenly over the x-axis range. (In many charts, the data points may not start or end at the axis end points, and the data points can be unevenly distributed.) If the x-coordinates are not provided, ChartDirector will put the data points at the default position x = 0, 1, 2, 3, ..... This is outside your axis range, and so the data points are not visible in the chart.
If your data points are in fact spreading evenly from $dataStart to $dataEnd, instead of using $c->addLineLayer($cic_ip,0x000080);, please use:
my $layer = $c->addLineLayer($cic_ip,0x000080);
$layer->setXData2($dataStart, $dataEnd);
Hope this can help.
Regards
Peter Kwan |
Re: setDateScale vs addLineLayer |
Posted by chris on Oct-03-2012 01:14 |
|
Thank you! That was it. |
|