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

Message ListMessage List     Post MessagePost Message

  data in weeks, labels in months
Posted by Gerard on Oct-14-2015 20:24
Attachments:
I have been struggling for quite a while with the following problem. I want to show in a barchart data per week (I use "default" weeks -> the week of Feb. 29 has eight days and week 52, eight days), but the labels should be monthly.
For now I have solved by showing for every week the d/mm (see http://trektellen.org/species/graph/1/-1/397/0), but actually i would like something as shown in the picture below.
Is this possible?
grafiek_tt.jpg

  Re: data in weeks, labels in months
Posted by Peter Kwan on Oct-15-2015 01:26
Attachments:
Hi Gerard,

There are many methods. I have just tried to create an extra x-axis at the bottom to show
the months and I got the chart as attached. As I am not sure which programming language
you are using, I just randomly use PHP to develop the code as attached. If you would like
the code in another language, please let me know.

Hope this can help.

Regards
Peter Kwan
simplebar.png
simplebar.php
<?php
require_once("../lib/phpchartdir.php");

for ($i = 0; $i < 52; ++$i)
{
	$data[$i] = $i + 10;
	$labels[$i] = " ";
}

$daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
for ($i = 0; $i < 12; ++$i)
	$weeksInMonth[$i] = $daysInMonth[$i] * 52 / 365;
	
# Create a XYChart object of size 250 x 250 pixels
$c = new XYChart(800, 250);

# Set the plotarea at (30, 20) and of size 200 x 200 pixels
$c->setPlotArea(50, 20, 720, 200);

# Add a bar chart layer using the given data
$c->addBarLayer($data);

# Set the labels on the x axis.
$c->xAxis->setLabels($labels);
$c->xAxis->setTickOffset(0.5);


$labelAxis = $c->addAxis(Bottom, 0);
$labelAxis->setLinearScale2(0, 51, array());
$labelAxis->setTickLength(10);

$monthNames = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

$xCoor = -0.5;
for ($i = 0; $i < 12; ++$i)
{
	$labelAxis->addLabel($xCoor + $weeksInMonth[$i] / 2, "~" . $monthNames[$i]);
	$xCoor += $weeksInMonth[$i];
	$labelAxis->addLabel($xCoor, " ");
}

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

  Re: data in weeks, labels in months
Posted by Gerard on Oct-15-2015 15:35
Wow, yes, great. Exactly what i want! Many thanks!! (Should have asked earlier :o)