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

(PHP version) Area chart show value 0 for null value. (Fixed by my own) #7

Open
sospixs opened this issue Nov 20, 2014 · 1 comment
Assignees

Comments

@sospixs
Copy link

sospixs commented Nov 20, 2014

Sometimes we want chat to show null value not zero in some reason.
In case of year on year compare (Jan-Dec) ex. 2013 vs 2014 sales performance accumulate.

Series 2013 will have all month jan-dec , But 2014 is not because current month is nov so dec will be null value not zero. If null value has covert to be zero the chart will show in the wrong meaning.

Code edit : ChartComponent.php
The original function code

  public function addSeries ($id, $name="", $seriesData = array(), $opts = array())
    {
        if(is_array($id)) {
            if(is_string($name)) {
                $name = array();
            }
            else {
                $name = is_array($name) ? $name : array();
            }
            $this->setOption("showLegendFlag", false);
            $this->addSeries ("series_0", "", $id, $name);
            return;
        }

    $seriesData = array_map('floatval', $seriesData);  
        $this->provide('series');
        $opts['seriesName'] = $name;
        $this->props->addItemToList('chart.series', $id, $opts);
        $this->data->addColumn($id, $seriesData);
    }

The new function code edit

     public function addSeries ($id, $name="", $seriesData = array(), $opts = array())
    {
        if(is_array($id)) {
            if(is_string($name)) {
                $name = array();
            }
            else {
                $name = is_array($name) ? $name : array();
            }
            $this->setOption("showLegendFlag", false);
            $this->addSeries ("series_0", "", $id, $name);
            return;
        }
// Add function to passing null value
            $func = function($value) {
                if (is_null($value))
                    return null;
                else return $value+0;
            };

        $seriesData = array_map( $func, $seriesData);  // Call function  
        $this->provide('series');
        $opts['seriesName'] = $name;
        $this->props->addItemToList('chart.series', $id, $opts);
        $this->data->addColumn($id, $seriesData);
    }

-Image compare before and after edit some code.
area-chart-show-zero-instead-null

@skyronic
Copy link
Member

Thanks for your code patch. We will incorporate it in a patch next week!

@skyronic skyronic self-assigned this Nov 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants