我正在使用chart,一个使用google chart tools的drupal模块。
我已经成功创建了图形,但我的问题是我想在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
答案 0 :(得分:0)
如果您申请https://www.drupal.org/node/536472中所述,则可以使用https://www.drupal.org/node/536472#comment-2127622中显示的示例来解决此问题。