Reputation: 3081
I am trying to create a bar chart using chart, a drupal module using google chart tools.
I can't figure out how to put labels under the bars. The labels should be 'a', 'b', and so on. For some reason, only the first label, 'a' is showing up on the x-axis and its straight in the center of the graph. Here is my code:
$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);
Upvotes: 1
Views: 560
Reputation: 303
In Drupal 6, I used CHART_TYPE_BAR_V instead of CHART_TYPE_BAR_V_GROUPED after applying this patch http://drupal.org/files/issues/chart.module-1169430.patch for the chart module,
$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');
For more details about this patch, refer to chart issue https://www.drupal.org/node/1169430
Upvotes: 2
Reputation: 303
chart_mixed_axis_label() method takes a second param in percentage to position the value.
Try giving percentage values.
chart_mixed_axis_label(t('a'), 10)
chart_mixed_axis_label(t('a'), 20)
chart_mixed_axis_label(t('a'), 30)
and so on.
Upvotes: 2