我試圖用jpgraph創建一個簡單的圖形(這對我來說是一個新東西,我用他們網站上的條形圖示例)並且想要y軸返回整個/四捨五入的數字。 所以我搜查了網頁,發現我必須使用textint。jpgraph textint y軸返回0f而不是數字
所以,現在我已經有了這兩條線:
$graph->SetScale("textint");
$graph->yaxis->SetTickPositions(array(0,1,2,3,4,5);
但不知何故,而不是返回一個整數的我現在得到0F關於y軸的每一步。 我只是想不通爲什麼它會導致成0F :( 是否有人對我有神奇的答案嗎?我在做什麼錯左右,使其結果存入值0F?
更多代碼:
$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;
}
編輯: 我而改變高度SETT只注意到現在開始顯示我期望的數字(現在500乘以180而不是500乘以200)。這是插件本身的錯誤嗎?