1

I need to inverse the data from my chart, like when I get the data from March 2015 to April 2014, I want that March 2015(actual time) to be on the right, not on the left. I'm using SVGGraph library. Thank you!

$graph = new SVGGraph($w, $h, $settings);
$data = [];
for ($i = 1; $i <= 12; $i++) {
    switch ($op) {
        case "eaqf-f":
            $data["$y-$m"] = StatUtil::getTotalEaInvoiced($y, $m, $oid);
            $data["$y-$m"] = $data["$y-$m"]['q'];
        break;

        case "cv-val":
            $data["$y-$m"] = StatUtil::getInvoicedCVs($y, $m, $oid);
        break;

        case "eaqf-r":
            $data["$y-$m"] = StatUtil::getTotalConsumption($y, $m, $oid);
        break;

        default: throw RuntimeException("Unsupported op: $op");
    }

    if (--$m == 0) {
        $m = 12;
        --$y;
    }
}

$graph ->Values($data);
$graph ->Render("Linegraph");
JAGUAR
  • 21
  • 5

1 Answers1

0
for ($i = 1; $i <= 12; $i++) {
$_key = sprintf('%1$04d-%2$02d', $y, $m);
    switch ($op) {
    case "eaqf-f":
        $data[$_key] = StatUtil::getTotalEaInvoiced($y, $m, $oid);
        $data[$_key] = $data[$_key]['q'];
        break;

and use ksort before the rendering

ksort($data, SORT_STRING);
JAGUAR
  • 21
  • 5