diff --git a/graphael.jquery.js b/graphael.jquery.js index 54f7fa2..e6f06ea 100644 --- a/graphael.jquery.js +++ b/graphael.jquery.js @@ -28,6 +28,9 @@ * 'opts': Options that are passed directly to the gRaphael method. * 'padding': Pixels of padding to add to the inside of the gRaphael element. * Defaults to 10. Set to 0 to draw the chart from edge to edge. + * 'label': Label information for barcharts, separated into 'values' + * (non-associative array) and 'isBottom' (flag to indicate if the + * labels must be located below the bars). * * Events * ------ @@ -139,6 +142,9 @@ switch (method) { case 'bar': chart = r.g.barchart(x, y, w, h, values, params.opts); + if (params.label) { + chart.label(params.label.values, params.label.isBottom); + } break; case 'dot': chart = r.g.dotchart(x, y, w, h, values[0], values[1], values[2], params.opts); diff --git a/graphael_example/graphael_example.graphs.inc b/graphael_example/graphael_example.graphs.inc index b78b7ac..a987847 100644 --- a/graphael_example/graphael_example.graphs.inc +++ b/graphael_example/graphael_example.graphs.inc @@ -22,6 +22,10 @@ function graphael_example_graphs_page() { 'opts' => array( 'gutter' => '80%', ), + 'label' => array( + 'values' => array('Africa', 'Asia', 'Europe', 'L. America', 'N. America', 'Oceania'), + 'isBottom' => TRUE, + ), ), array( 'label' => array( 'values' => array('Africa', 'Asia', 'Europe', 'Latin America', 'Northern America', 'Oceania'), @@ -32,6 +36,36 @@ function graphael_example_graphs_page() { ), )); + $output[] = '

' . t('World population by continent, grouped bars') . '

'; + + $output[] = theme('graphael', 'bar', array($popdata[1750], $popdata[1800], $popdata[1850], $popdata[1900], $popdata[1950], $popdata[2000]), array( + 'colors' => array('#490A3D', '#BD1550', '#E97F02', '#F8CA00', '#8A9B0F', '#68B3AF'), + 'font' => '10px Arial, sans-serif', + 'opts' => array( + 'gutter' => '10%', + ), + 'padding' => 20, + // GRaphael breaks when trying to use label data for grouped barcharts. + // 'label' => array( + // 'values' => array('Africa', 'Asia', 'Europe', 'L. America', 'N. America', 'Oceania'), + // 'isBottom' => true, + // ), + ), array( + 'label' => array( + 'values' => array('Africa', 'Asia', 'Europe', 'L. America', 'N. America', 'Oceania'), + 'params' => array( + 'attrText' => array( + 'fill' => '#aaa', + 'font' => '12px Arial, sans-serif', + ), + 'label' => 'label', + 'attrLabel' => array( + 'fill' => '#000', + ), + ), + ), + )); + $output[] = '

' . t('Population growth by continent') . '

'; $x_axis = array_keys($popdata);