Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard graph has broken y-axis range #7927

Closed
tomasinchoo opened this issue Dec 22, 2016 · 10 comments
Closed

Dashboard graph has broken y-axis range #7927

tomasinchoo opened this issue Dec 22, 2016 · 10 comments
Assignees
Labels
bug report Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@tomasinchoo
Copy link

tomasinchoo commented Dec 22, 2016

Y-axis on dashboard graph always shows range 0 to 100 in steps of 10. That means quantity and amounts do not match actual value in graph.

Preconditions

  1. Any working setup for Magento 2
  2. Tested on 2.1.1, but it probably doesn't work in any other

Steps to reproduce

  1. Make few orders and look at the graph in admin dashboard

Expected result

  1. Values shown should be matched with y-axis value

Actual result

  1. It always show range 10 to 100 in steps of 10 and values (qty and amounts) doesn't make sense with that values

Fortunately, that issue is easy to fix:
This code (exists in M1, not in M2) needs to be inserted on line 424 in vendor/magento/module-backend/Block/Dashboard/Graph.php (thanks to @ivanweiler)

                } else if ($idx == 'y') {
                    $valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);   
@bardkalbakk
Copy link

What's the status on this bug? Still an issue in 2.1.5 believe.

@sennin32
Copy link

2.1.6 still has the same issue.

@veloraven
Copy link
Contributor

Internal ticket was created - MAGETWO-69966

@veloraven veloraven added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 19, 2017
@Silarn
Copy link

Silarn commented Jun 28, 2017

Here's a plugin solution for this issue until the official fix:

    public function __construct(
        \Magento\Backend\Helper\Dashboard\Data $dashboardData,
        \Magento\Framework\UrlInterface $url
    )
    {
        $this->_dashboardData = $dashboardData;
        $this->_urlBuilder = $url;
    }
    public function aroundGetChartUrl(\Magento\Backend\Block\Dashboard\Graph $graph, \Closure $proceed, $directUrl = true)
    {
        $query = $proceed();
        $series = $graph->getAllSeries();
        $localmaxvalue = [0];
        $localminvalue = [0];
        foreach ($series as $index => $serie) {
            $localmaxvalue[$index] = max($serie);
            $localminvalue[$index] = min($serie);
        }
        $maxvalue = max($localmaxvalue);
        $minvalue = min($localminvalue);
        $miny = 0;
        $maxy = 0;
        if ($minvalue >= 0 && $maxvalue >= 0) {
            if ($maxvalue > 10) {
                $p = pow(10, $this->_getPow($maxvalue));
                $maxy = ceil($maxvalue / $p) * $p;
            } else {
                $maxy = ceil($maxvalue + 1);
            }
        }
        $params = array('chxr' => "1,$miny,$maxy");
        // return the encoded data
        if ($directUrl) {
            return $query.'&chxr='.$params['chxr'];
        } else {
            $parts = parse_url($query);
            parse_str($parts['query'], $parsedParams);
            $params = array_merge($params, $parsedParams);
            $gaData = urlencode(base64_encode(json_encode($params)));
            $gaHash = $this->_dashboardData->getChartDataHash($gaData);
            $params = ['ga' => $gaData, 'h' => $gaHash];
            return $this->_urlBuilder->getUrl('adminhtml/*/tunnel', ['_query' => $params]);
        }
    }
    protected function _getPow($number)
    {
        $pow = 0;
        while ($number >= 10) {
            $number = $number / 10;
            $pow++;
        }
        return $pow;
    }

(Also thanks in part to @thaisatservermonkey)

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Sep 11, 2017
@magento-engcom-team
Copy link
Contributor

@tomasinchoo, thank you for your report.
We've created internal ticket(s) MAGETWO-69966 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 11, 2017
@osrecio
Copy link
Member

osrecio commented Oct 25, 2017

Working on it, to implement solution of Silarn or tomasinchoo

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-82762

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-82761

@okorshenko
Copy link
Contributor

The issue has been fixed in 2.2-develop branch and will be available with 2.2.2 release soon

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-82760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

9 participants