|
Shaded area and extra line |
Posted by Leo on Apr-13-2012 01:33 |
|
Hello, Peter,
1. the shaded area is not completely shaded red, note that it is a splined area
2. there is a extra vertical line shown up at the end, but when
"$c->addAreaLayer($data, $c->yZoneColor(0, 0xff0000, -1));"
is *not* called, the line won't show
code:
1 #!/usr/bin/perl
2 use perlchartdir;
3
4 # The data for the line chart
5 my $data = [DATAPOINTS];
6 #my $data = [-100, 100, 20, -1, 44, -29];
7
8 # The labels for the line chart
9 my $labels = [LABELPOINTS];
10
11 # Create a XYChart object of size 250 x 250 pixels
12 my $c = new XYChart(500, 250);
13
14 # Set the plotarea at (30, 20) and of size 200 x 200 pixels
15 #$c->setPlotArea(30, 20, 200, 200);
16 $c->setPlotArea(-1, -1, 500, 250, 0xdddddd, 0xdddddd, 0xdddddd, 0xdddddd);
17
18 # Add a line chart layer using the given data
19 $layer = $c->addSplineLayer($data, 0x330099);
20
21 # Set the labels on the x axis.
22 $c->xAxis()->setLabels($labels);
23
24 $c->yAxis()->addMark(0, 0xff0000, "0")->setLineWidth(3);
25
26 #$c->yAxis->setLogScale2();
27 #$c->yAxis->setLogScale();
28
29 $c->addAreaLayer($data, $c->yZoneColor(0, 0xff0000, -1));
30
31 $layer->setLineWidth(10);
32
33 # Display 1 out of 3 labels on the x-axis.
34 $c->xAxis()->setLabelStep(3);
35
36 # Output the chart
37 $c->makeChart("1_PNG")
|
Re: Shaded area and extra line |
Posted by Peter Kwan on Apr-14-2012 00:44 |
|
Hi Leo,
Your current code is shading the area layer, not the spline layer. In the spline layer, spline curves are used to join the points. In an area layer, straight lines are used to join the points. As the area layer is different from the spline layer, it is normal that the shaded red is not bounded by the spline.
To shade the spline layer, the area layer should not be used. Instead, please use the following code:
$layer = $c->addSplineLayer($data, 0x330099);
$c->xAxis()->setLabels($labels);
$mark = $c->yAxis()->addMark(0, 0xff0000, "0")->setLineWidth(3);
$c->addInterLineLayer($layer->getLine(), $mark->getLine(), 0xff0000, $perlchartdir::Transparent);
The vertical line at the end is part of the area layer. It is the border of the area. That's why if you do not use the area layer, the border will disappear. (If you would like to use the area layer for some reasons, you may use Layer.setBorderColor to set the border color to transparent.)
Hope this can help.
Regards
Peter Kwan |
|