|
addMark doesn't work properly with date formats in perl |
Posted by Peter on May-01-2012 22:03 |
|
Hi,
I'm trying to add Vertical lines from xAxis using addMark. I have the following details:
1. Date format is in mm-dd-yyyy format, using perlchartdir::chartTime($yy, $mm, $dd).
2. Following is the code that I'm using for adding the mark line:
if ($x_format eq "mmddyy") {
my ($mm, $dd, $yy) = &jd_cal($when); # Conversion from Julian format
my $ymark = $c->xAxis()->addMark($c->formatValue(perlchartdir::chartTime($yy,
$mm, $dd), "{value|mm-dd-yyyy}"), 0x000000, $label);
$ymark->setLineWidth(2);
$ymark->setDrawOnTop(false);
$ymark->setFontAngle(90);
if ($top == 1) {
$ymark->setAlignment($perlchartdir::TopRight);
} elsif ($top == 0) {
$ymark->setAlignment($perlchartdir::BottomRight);
}
}
3. This is how the x-labels are updated:
foreach (@xvals) {
($mm, $dd, $yy) = &jd_cal($_);
push (@tmp_dates, perlchartdir::chartTime($yy, $mm, $dd));
}
@xvals = [];
@xvals = @tmp_dates;
if ($x_format eq "mmddyy") {
$c->xAxis()->setLabels2(\\@xvals);
$c->xAxis()->setLabelFormat("{value|mm-dd-yyyy}");
}
But the problem is that the mark line doesn't come up correctly, that is if I want the
mark line to be on say 02-08-2012, the line is drawn on 02-15-2012 and I'm not sure
why this happens. Also another example is, if I want the mark on 03-21-2012, the line
comes up at 02-22-2012.
Please let me know what am I doing wrong?
Thanks,
Peter |
Re: addMark doesn't work properly with date formats in perl |
Posted by Peter on May-02-2012 01:32 |
|
I Tried using various alignment of code too, like populating the xAxis labels first and then
use the addMark and vice versa.
When I use the addMark first and then populate the xAxis labels, then the labels are
displayed correctly with the addMark line and the same issue with the line not being in the
correct place comes up.
When I use the addMark after populating the xAxis labels, then the addMark line comes up
without the xAxis labels. Not sure what I'm doing wrong.
Please let me know.
Thanks,
Peter |
Re: addMark doesn't work properly with date formats in perl |
Posted by Peter on May-02-2012 02:48 |
|
Ok, after reading various posts I got to know that using setLabels2 doesn't work in case of
understanding the index for setting the addMark.
So we need to use setDateScale or setDateScale2 or other equivalents.
Now when I use the setDateScale, I have converted all the Julian format dates to Perl
Chart Director format and put it up in an array, so this would show up the labels as the
Perl ChartTime format. But I want this in the ("mm-dd-yyyy") format.
I tried creating a separate array with the labels in that format and then tried passing in
case of the setDateScale2 (lowlimit, highlimit, string array), but this didn't matter as the
the low and high limits where in chartTime format.
How do I get the xAxis labels in the correct format and also use the addMark
appropriately.
Thanks,
Peter |
Re: addMark doesn't work properly with date formats in perl |
Posted by Peter on May-02-2012 04:18 |
|
Hi Peter,
Tried the following:
$c->xAxis()->setDateScale($xvals[0], $xvals[$#xvals], 86400 * 7);
$c->xAxis()->setMultiFormat2(perlchartdir::AllPassFilter, "{value|mm-dd-yyyy}",);
Now the addMark seems to work fine, but the line chart is no more visible. That is when I
try using the
my $layer1 = $c->addLineLayer(\\@yvals, -1, "$desc");
it only shows the vertical line from addMark, but I don't get to see the Line layer.
Any idea what I'm doing wrong??
Regards,
Peter |
Re: addMark doesn't work properly with date formats in perl |
Posted by Peter Kwan on May-03-2012 00:53 |
|
Hi Peter,
If you prefer to use setDateScale, the code should be something like:
#set up the axis scale and axis labels
$c->xAxis()->setDateScale($xvals[0], $xvals[$#xvals], 86400 * 7);
$c->xAxis()->setMultiFormat2(perlchartdir::AllPassFilter, "{value|mm-dd-yyyy}",);
my $layer1 = $c->addLineLayer(\\@yvals, -1, "$desc");
$layer1->setXData(\\@xvals);
.... add mark using date/time ....
If you prefer to use a label based x-axis (like in your original code), you can use the index of the label as the mark position. It is like:
my $myMarkPos = perlchartdir::chartTime($yy, $mm, $dd);
for (my $i = 0; $i < scalar(@xvals); ++$i) {
if ($myMarkPos == $xvals[$i]) {
my $ymark = $c->addMark($i, ......);
.... configure the mark .....
break;
}
}
Hope this can help.
Regards
Peter Kwan |
Re: addMark doesn't work properly with date formats in perl |
Posted by Peter on May-03-2012 15:00 |
|
Hi Peter,
I have already modified the code to work with index. But the issue that I saw with
setDateScale was about, the addMark working correctly and the line graph not rendering.
So I will only see the vertical line on the graph but I won't get the line graph rendering,
not sure why this happened.
Also wanted to know how I use the same method for drawing line graphs for both left and
right y axis, i.e, I would want one line generated to use the data from yAxis() and the
other line generated to use yAxis2() data.
I have dual axis graphs where I've to combine bar/sbar and line/rline graphs. So can you
suggest what I can use for alternate between yAxis data??
Thanks,
Peter |
Re: addMark doesn't work properly with date formats in perl |
Posted by Peter on May-03-2012 15:44 |
|
Hi Peter,
Thanks a lot for your help. It's working fine now.
Also I figured out to use the "$layer2->setUseYAxis2();" option, to use the yAxis2() for the
line charts.
Thanks again.
Regards,
Peter |
|