Drupal google Chart api Y 轴值需要帮助
我正在使用 chart,这是一个使用 Google 图表工具。
我已经成功创建了图表,但我的问题是我想在 Y 轴上放置整数值。我正在制作一张总票数图表。假设我有一个有 55 票(总数)的民意调查。 Y 轴范围应直到最大值属性。就像如果我们有 A、B 和 C,那么 A 有 25 票,B 有 10 票,C 有 20 票。因此,Y 轴范围应等于 25,并且它们之间没有 1.5 或 2.5 等浮点值。这是我的函数的代码:
//theme the poll results block
$html = $variables['results'];
$pattern = "@class=\"text\"\>(.*)\</div\>@";
preg_match_all($pattern, $html, $choices); //extract choices
$pattern = "@style=\"width: (.*)%;\"@";
preg_match_all($pattern, $html, $votes); //extract percentages
$chart = array(
'#chart_id' => 'poll_chart' . $variables[nid],
'#type' => CHART_TYPE_BAR_V,
'#size' => chart_size(600, 350),
'#grid_lines' => chart_grid_lines(100,10 ),
'#bar_size' => chart_bar_size(30, 50),
);
// NEED TO FILL IN DATA TO MAKE CHART
for ($c=0; $c < count($choices[1]); $c++) { //make labels and values
$chart['#data_colors'][] = 'ff8e07';
$chart['#data'][$choices[1][$c]] = $votes[1][$c]; //number of votes
$chart['#legends'][] = $choices[1][$c] . " (" . $votes[1][$c] . "%)"; // labels
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t($choices[1][$c]))
;
print $choice['chvotes'];
}
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][2][] = chart_mixed_axis_label(t('Choices'), 50);
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][3][] = chart_mixed_axis_label(t('Votes'), 95);
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][4][] = chart_mixed_axis_range_label(0, $variables['votes']);
$variables['results'] = chart_render($chart); //render graph
I am using chart, a drupal module using google chart tools.
I have created the graph successfully but my problem is that I want to put integer values in the Y axis. I am making a graph of total number of votes. So let's suppose I have a poll with 55 votes (total nummer). The Y axis range should be till the max value property. Like if we have A, B and C then A has 25 votes, B has 10 votes and C has 20 votes. So the Y axis range should be equal to 25 with no float values like 1.5 or 2.5 between them. Here is the code of my function:
//theme the poll results block
$html = $variables['results'];
$pattern = "@class=\"text\"\>(.*)\</div\>@";
preg_match_all($pattern, $html, $choices); //extract choices
$pattern = "@style=\"width: (.*)%;\"@";
preg_match_all($pattern, $html, $votes); //extract percentages
$chart = array(
'#chart_id' => 'poll_chart' . $variables[nid],
'#type' => CHART_TYPE_BAR_V,
'#size' => chart_size(600, 350),
'#grid_lines' => chart_grid_lines(100,10 ),
'#bar_size' => chart_bar_size(30, 50),
);
// NEED TO FILL IN DATA TO MAKE CHART
for ($c=0; $c < count($choices[1]); $c++) { //make labels and values
$chart['#data_colors'][] = 'ff8e07';
$chart['#data'][$choices[1][$c]] = $votes[1][$c]; //number of votes
$chart['#legends'][] = $choices[1][$c] . " (" . $votes[1][$c] . "%)"; // labels
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t($choices[1][$c]))
;
print $choice['chvotes'];
}
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][2][] = chart_mixed_axis_label(t('Choices'), 50);
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][3][] = chart_mixed_axis_label(t('Votes'), 95);
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][4][] = chart_mixed_axis_range_label(0, $variables['votes']);
$variables['results'] = chart_render($chart); //render graph
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您按照 https://www.drupal.org/node/536472 中所述进行应用,则https://www.drupal.org/node/536472#comment-2127622<中显示的示例/a> 可以用来解决这个问题。
If you apply described in https://www.drupal.org/node/536472, then the sample shown in https://www.drupal.org/node/536472#comment-2127622 can be used to address this question.