Question

how can i tell jpgraph to show x-axis ticks every month? I have two charts, in one i show results from 1 year and on other i show results from beginning to end. On year graph it shows weekly results and i like it but in case of showing bigger date range (in my case from 1.4.2010. till 10.1.2013. it show tick only every one year so i have tick on 1.4.2010, 1.4.2011, ...

Important part of the code where i define x-axis properties:

$graph->xaxis->SetTickLabels($timestamp);
$graph->xaxis->scale->SetDateAlign(MONTHADJ_1);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();

Timestamp array is unix timestamp values converted from mysql dates,and timestamps are correct. I checked them. Also results in the graphs are fine, only i want more ticks on x axis.

Was it helpful?

Solution

To answer my own question,and close it, here is what i added (combined with old xaxis properties):

require_once ('jpgraph/jpgraph_utils.inc.php');

$dateUtils = new DateScaleUtils();
list($tickPos,$minTickPos) = $dateUtils->getTicks($timestamp,DSUTILS_MONTH1);

$graph->xaxis->SetTickPositions($tickPos,$minTickPos);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();

Also i changed scale of graph to intlin, it was datlin before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top