ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  setXdata2 displaying odd months not even... also not aligned...
Posted by VeNoMouS on Dec-13-2011 12:48
Attachments:
This is in perl btw.

my $c = new XYChart(800, 400);
$c->setBackground($c->linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888);
$c->setRoundedFrame();
$c->setDropShadow();
$c->addTitle("Yearly Closed Tickets", "timesbi.ttf", 18)->setMargin2(0, 0, 16, 0);
my $plotArea = $c->setPlotArea(60, 100, 710, 275, -1, -1, $perlchartdir::Transparent,$c-
>dashLineColor(0x444444, 0x000101), -1);

my $legendBox = $c->addLegend($plotArea->getLeftX() + $plotArea->getWidth() / 2, 45,0,
"arialbd.ttf", 10);
$legendBox->setAlignment($perlchartdir::TopCenter);
$legendBox->setBackground($perlchartdir::Transparent, $perlchartdir::Transparent);

$c->yAxis()->setTickDensity(30);
$c->xAxis()->setTickDensity(75);

$c->xAxis()->setColors($perlchartdir::Transparent);
$c->yAxis()->setColors($perlchartdir::Transparent);

$c->xAxis()->setMargin(15, 15);

$c->xAxis()->setLabelStyle("arialbd.ttf", 8);
$c->yAxis()->setLabelStyle("arialbd.ttf", 8);
$c->yAxis2()->setLabelStyle("arialbd.ttf", 8);
$c->yAxis()->setTitle("Amount", "arialbi.ttf", 10);

foreach my $group (keys %fieldforce_groups)
{
my $data_set;
my $z=0;
foreach my $date (sort{ lc($a) cmp lc($b) } keys %{$Yearly_Hash{$group}})
{
print "[$z] ".$Yearly_Hash{$group}{$date}."\\n";

push(@{$data_set},$Yearly_Hash{$group}{$date});
$z++;
}

print "z total = $z\\n";
$start=UnixDate("1 year ago", "%Y-%m-%d");
print "Start = $start\\n";
$start =~ /^(.*?)-(.*?)-(.*?)$/;
my $dataStart = perlchartdir::chartTime($1, $2, $3);

$end=UnixDate("0 months ago", "%Y-%m-%d");
print "End = $end\\n";
$end =~ /^(.*?)-(.*?)-(.*?)$/;
my $dataEnd = perlchartdir::chartTime($1, $2, $3);

my $layer1 = $c->addLineLayer2();
$layer1->addDataSet($data_set, -1, $group)-
>setDataSymbol($perlchartdir::GlassSphere2Shape, 11);
$layer1->setXData2($dataStart, $dataEnd);
$layer1->setLineWidth(3);

}
$c->makeChart("Yearly.png");


[0] 0
[1] 1
[2] 2
[3] 10
[4] 28
[5] 39
[6] 30
[7] 16
[8] 58
[9] 70
[10] 106
[11] 96
[12] 50
z total = 13
Start = 2010-12-13
End = 2011-12-13

[0] 19
[1] 61
[2] 86
[3] 70
[4] 62
[5] 134
[6] 94
[7] 76
[8] 42
[9] 99
[10] 63
[11] 75
[12] 32
z total = 13
Start = 2010-12-13
End = 2011-12-13


Yet other graphs I've generated via weekly come out fine....
Yearly.png

  Re: setXdata2 displaying odd months not even... also not aligned...
Posted by Peter Kwan on Dec-14-2011 02:30
Hi VeNoMouS,

For your case, you have use "setTickDensity(75)", so ChartDirector will reserve at least 75 pixels per label. Your plot area is 710 pixels wide, so it can have at most 710 / 75 = 9 labels. Therefore, using monthly labels is not feasible as at most 9 labels can be fitted. That's why ChartDirector chooses bi-monthly labels.

Also, in your case, you are using a true date/time axis. ChartDirector by default will put the labels at "natural boundary positions". For monthly labels, the labels will be at Jan 01, 2011 00:00:00, Feb 01, 2011 00:00:00, ... etc.. It does not matter what is the actual position of your data points. The same happens to the y-axis too. For example, you can see the y-axis labels at 0, 20, 40, 60, ... even though your data points are not at those positions. In other words, it is normally that the x-axis and y-axis labels are not aligned exactly with any data point.

If in your case, you would like the labels to align with the data points, you may tell ChartDirector replace the line "$c->xAxis()->setTickDensity(75);" with:

$c->xAxis()->setDateScale($dataStart, $dataEnd, 30 * 86400);

Hope this can help.

Regards
Peter Kwan

  Re: setXdata2 displaying odd months not even... also not aligned...
Posted by VeNoMouS on Dec-14-2011 04:30
Attachments:
Doing so with setDateScale and without setTickDensity screws up the dates as it displays a weird
order as per attached, how ever , removing setDateScale and setTickDensity seems to display a
more desirable look as can be seen in attachment Yearly_2.png.

Thanks for you help tho :)
Yearly.png
Yearly_2.png

  Re: setXdata2 displaying odd months not even... also not aligned...
Posted by Peter Kwan on Dec-14-2011 04:57
Hi VeNoMouS,

Some labels were missing in your first chart because there is insufficient space for the labels (the labels are starting to overlap), so some labels are removed. (That's why in the original code ChartDirector chooses bi-monthly labels.)

All labels are shown in the second chart because the labels are shorter and so they do not overlap. The labels are shorter because all labels are at the start of a month, and in this case, ChartDirector will automatically remove the day part of the label. Instead of  "mm/dd/yyyy", ChartDirector will use "mm/yyyy", understanding that it refers to the first day of a month.

On the other hand, ChartDirector uses "mm/dd/yyyy" for the first chart, because the labels are at the middle of the month, so it needs to also include the "day" in the label and this makes them longer.

If you would prefer the first chart, but want to show all labels, you may:

(a) Use a shorter label format, like "mm/dd/yy", or "mm/dd" or "mm/yyyy". For example:

$c->xAxis()->setLabelFormat("{value|mm/dd/yy}");

(b) Use a smaller font (eg. Arial Bold 7pts, or you may try non-bold fonts). If the font is small enough, there will be sufficient space for all the labels.

(c) Use a wide plot area to provide more space for the labels.

Hope this can help.

Regards
Peter Kwan