Growth percentage in charts

(4 posts) (2 voices)

Tags:

No tags yet.

  1. Dev, Member

    Hi,

    How can I show growth percentages in bar or column charts? I couldn't find anything related to it in the documentation. Please share or guide me on how this can be achieved.

    Reference: [https://images.app.goo.gl/g72GEkpfC9UC1BPT8]

    Any help would be helpful.

    Thank you

  2. myDBR Team, Key Master

    The chart is a basic column chart with custom arrows and text.

    You can create a myDBR column chart using ChartDirector, and use the BaseChart.addLine and BaseChart.addText functions to add the necessary additional information. You'll need to calculate the positions for the arrows and text using the ChartDirector API.

    See a demo.
    --
    myDBR Team

  3. Dev, Member

    The exact same query returns an empty screen instead of displaying the chart. It works fine without the ChartDirector query, but it doesn't return anything when the ChartDirector query is included. I apologize if I’m not explaining this clearly. I would appreciate any help you can provide.

    SELECT 'dbr.chart', 'Column', 'Growth Percentage';
    SELECT 'dbr.chart.options', 'bargap', 0.35;
    SELECT 'dbr.chart.options', 'chartdirector', '
    $decline_color = 0x33CC33;
    $growth_color = 0xFF1D1D;
    $arrow_color = 0x000000;

    for ($ds=0; $ds < $layer->getDataSetCount()-1; $ds++) {
    $fromVal = $layer->getDataSet($ds)->getValue($ds);
    $toVal = $layer->getDataSet($ds+1)->getValue($ds+1);

    $same_value = $fromVal==$toVal;
    $percent = sprintf("%+d%%", -1* round(($toVal - $fromVal)/$fromVal*100,0));

    $x = $c->getXCoor($ds)+($c->getXCoor($ds+1)-$c->getXCoor($ds))/2;
    if ($fromVal!=$toVal) {
    $c->addLine( $x, $c->getYCoor($fromVal), $x, $c->getYCoor($toVal), $arrow_color,3 );
    }

    if ($fromVal<=$toVal) {
    if (!$same_value) {
    $c->addLine( $x+4, $c->getYCoor($toVal)+4, $x, $c->getYCoor($toVal), $arrow_color,3 );
    $c->addLine( $x, $c->getYCoor($toVal), $x-4, $c->getYCoor($toVal)+4, $arrow_color,3 );
    }
    $c->addText($x, $c->getYCoor($toVal)-14, $percent, "", 8, $same_value ? 0x000000 : $decline_color, TopCenter);
    } else {
    $c->addLine( $x-4, $c->getYCoor($toVal)-4, $x, $c->getYCoor($toVal), $arrow_color,3 );
    $c->addLine( $x, $c->getYCoor($toVal), $x+4, $c->getYCoor($toVal)-4, $arrow_color,3 );
    $c->addText($x, $c->getYCoor($toVal)+14, $percent, "", 8, $growth_color, BottomCenter);
    }
    }
    ';

    SELECT 'Jan' as d, 15 as v
    UNION
    SELECT 'Feb', 20
    UNION
    SELECT 'March', 05
    UNION
    SELECT 'April', 25
    UNION
    SELECT 'May', 50
    ;

  4. myDBR Team, Key Master

    Do you have the ChartDirector PHP extension installed and what is the chosen default chart module in Environmental Settings?

    Btw, you are missing the 'after' option at the end of the chartdirector command.

    myDBR Team


Reply

You must log in to post.