I'm trying to create a simple graph with jpgraph (which is a new thing for me, I've used the example for the bars graph from their website.) and want the y-axis to return whole/rounded numbers. So I've searched the web and found out I have to use textint.
So now I've got these 2 lines:
$graph->SetScale("textint");
$graph->yaxis->SetTickPositions(array(0,1,2,3,4,5);
But somehow instead of returning a whole number I now get 0f for every step on the y-axis. I just can't figure out why it results into a 0f :( Does somebody have the magical answer for me? What am I doing wrong or so to make it result into the value 0f?
More code:
$graphSettings = [
'tick_positions' => [0, 1, 2, 3, 4, 5],
'tick_labels' => ['Q1 2017', 'Q2 2017', 'Q3 2017', 'Q4 2017', 'Q1 2018'],
];
$graphs = [];
foreach ($questions as $key => $question) {
$graphs[] = $this->generateGraph($graphSettings, $question, $key);
}
public function generateGraph($settings, $question, $key) {
$data1y = $question['bar_plots']; // height of bars
// Create the graph. These two calls are always required
$graph = new \Graph(500, 200, 'auto');
$graph->SetScale("textint");
$theme_class = new \UniversalTheme;
$graph->SetTheme($theme_class);
$graph->yaxis->SetTickPositions($settings['tick_positions']); // array y numbers, array y between dashes
$graph->SetBox(false);
$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels($settings['tick_labels']);
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false, false);
// Create the bar plots
$b1plot = new \BarPlot($data1y);
// ...and add it to the graPH
$graph->Add($b1plot);
$b1plot->SetColor("white");
$b1plot->SetFillColor("#41b6e6");
// Return the graph
$contentType = 'image/png';
ob_start();
$graph->Stroke();
$image_data = ob_get_clean();
$str = "data:$contentType;base64," . base64_encode($image_data);
return $str;
}
Edit: I just noticed while changing the height setting of the graphs (now 500 by 180 instead of 500 by 200) that it now started to show the numbers I was expecting. Is this a bug in the plugin itself?