【发布时间】:2018-01-11 07:35:00
【问题描述】:
我正在尝试使用 jpgraph 创建一个简单的图形(这对我来说是一个新事物,我使用了他们网站上的条形图示例。)并希望 y 轴返回整数/四舍五入的数字. 所以我搜索了网络,发现我必须使用 textint。
所以现在我有了这两行:
$graph->SetScale("textint");
$graph->yaxis->SetTickPositions(array(0,1,2,3,4,5);
但不知何故,我现在在 y 轴上的每一步都得到 0f,而不是返回一个整数。 我只是无法弄清楚为什么它会导致 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;
}
编辑: 我刚刚注意到,在更改图表的高度设置(现在是 500 x 180 而不是 500 x 200)时,它现在开始显示我期望的数字。这是插件本身的错误吗?
【问题讨论】: