1

我正在尝试使用图表创建条形图,这是一个使用谷歌图表工具的 drupal 模块。

我不知道如何在栏下放置标签。标签应该是“a”、“b”等。出于某种原因,只有第一个标签“a”显示在 x 轴上,并且它的直线显示在图形的中心。这是我的代码:

$chart = array(
  '#chart_id' => 'test_chart2',
  '#title' => chart_title(t('Bar Chart'), '0000ee', 15),
  '#type' => CHART_TYPE_BAR_V_GROUPED,
  '#size' => chart_size(400, 200),
  '#grid_lines' => chart_grid_lines(10, 10),
  '#bar_size' => chart_bar_size(25, 5),

 );

  $chart['#data'][] = array(10);
  $chart['#data'][] = array(20);
  $chart['#data'][] = array(30);
  $chart['#data'][] = array(40);
  $chart['#data'][] = array(50);
  $chart['#data'][] = array(60);
  $chart['#data'][] = array(70);
  $chart['#data'][] = array(80);

  $chart['#data_colors'][] = chart_unique_color('test_a');
  $chart['#data_colors'][] = chart_unique_color('test_b');
  $chart['#data_colors'][] = chart_unique_color('test_c');

  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] =   chart_mixed_axis_range_label(0, 200);
  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][3][] = chart_mixed_axis_label(t('Hours'), 95);

  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][4][] = chart_mixed_axis_label(t('a'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][5][] = chart_mixed_axis_label(t('b'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][6][] = chart_mixed_axis_label(t('c'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][7][] = chart_mixed_axis_label(t('d'));  
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][8][] = chart_mixed_axis_label(t('e'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][9][] = chart_mixed_axis_label(t('f'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][10][] = chart_mixed_axis_label(t('g'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][11][] = chart_mixed_axis_label(t('h'));


  return chart_render($chart);
4

2 回答 2

2

在 Drupal 6 中,在为图表模块应用此补丁http://drupal.org/files/issues/chart.module-1169430.patch后,我使用了 CHART_TYPE_BAR_V 而不是 CHART_TYPE_BAR_V_GROUPED ,

$chart = array(
    '#chart_id' => $chart_id,
    '#title' => $title,
    '#type' => CHART_TYPE_BAR_V,
    '#size' => chart_size(700, 400),
    '#grid_lines' => chart_grid_lines(10, 10),
    '#bar_size' => chart_bar_size(55, 15),
  );
$chart['#data'][] = 10;
$chart['#data'][] = 20;
$chart['#data_colors'][] = C1;
$chart['#data_colors'][] = C2;
$chart['#mixed_axis_labels'][CHART_AXIS_X_TOP][1][] = chart_mixed_axis_label('a');
$chart['#mixed_axis_labels'][CHART_AXIS_X_TOP][1][] = chart_mixed_axis_label('b');

有关此补丁的更多详细信息,请参阅图表问题https://www.drupal.org/node/1169430

于 2012-12-28T06:37:06.907 回答
2

chart_mixed_axis_label() 方法采用第二个百分比参数来定位值。

尝试给出百分比值。

chart_mixed_axis_label(t('a'), 10)
chart_mixed_axis_label(t('a'), 20)
chart_mixed_axis_label(t('a'), 30) 

等等。

于 2012-12-27T08:03:51.077 回答