Hi Leo,
1. You may use a scatter layer to add a symbol at any position you like. For example, to add it at the last data point for the "Simple Line Chart", you may use:
my $lastXCoor = scalar(@$data) - 1;
$c->addScatterLayer([$lastXCoor], [$$data[$lastXCoor]], "", $perlchartdir::CircleSymbol, 11, 0x000000, 0x000000);
Please put the above code before addLineLayer if you want to symbol to stay on top of the line (instead of under it).
2. The code is like:
use perlchartdir;
# The data for the line chart
my $data = [2130, 2128, 2140, 2155, 2175, 2168, 2154, 2160, 2150, 2162, 2175, 2165,
2175, 2191, 2160, 2155, 2153, 2135, 2150, 2166, 2156, 2148, 2152, 2165, 2201];
my $labels = [];
my $currentTime = 9 * 60 + 28;
for(my $i = 0; $i < 148; ++$i) {
if ($currentTime % 120 == 0) {
if ($currentTime == 12 * 60) {
push @$labels, " 12pm"
} elsif ($currentTime > 12 * 60) {
push @$labels, sprintf(" %dpm", $currentTime / 60 - 12);
} else {
push @$labels, sprintf(" %dam", $currentTime / 60);
}
} elsif ($currentTime % 60 == 0) {
push @$labels, "-";
} else {
push @$labels, "";
}
$currentTime += 4;
}
my $c = new XYChart(200, 100);
$c->addText(36, 3, "NASFQ @ 2:30 pm (C) WXYZA", "", 7.5);
$c->setPlotArea(40, 17, 146, 66);
#left y-axis
$c->yAxis()->setLabelStyle("", 7.5);
$c->yAxis()->setTickLength(-3);
$c->yAxis()->setAutoScale(0, 0, 0);
#right y-axis (for the ticks)
$c->syncYAxis();
$c->yAxis2()->setTickLength(-3);
$c->yAxis2()->setLabelFormat(" ");
#bottom x-axis
$c->xAxis()->setLabels($labels);
$c->xAxis()->setLabelStyle("", 7.5);
$c->xAxis()->setTickLength(-4);
#top x-axis (for the ticks)
$c->xAxis2()->setLabels($labels);
$c->xAxis2()->setTickLength(-4);
$c->xAxis2()->setColors($perlchartdir::LineColor, 0xffffff);
$c->addLineLayer($data, 0x3333ff);
$c->yAxis()->addMark(2167, 0xff0000);
# Output the chart
$c->makeChart("minichart.png");
Hope this can help.
Regards
Peter Kwan |