如何使用drupal模块图表为x轴分配标签?

时间:2012-08-21 17:10:47

标签: charts google-visualization drupal-6

我正在尝试使用chart创建一个条形图,这是一个使用google chart tools的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);

2 个答案:

答案 0 :(得分: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) 

等等。

答案 1 :(得分: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