kevinkhill / lavacharts

Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.
http://lavacharts.com
Other
620 stars 142 forks source link

Dashboard / ChartWrapper missing functionality #341

Closed am-css closed 2 years ago

am-css commented 3 years ago

What Version? 3.1.14

Issue

Trying to build a dashboard with a data set [ 'date', 'item', 'value' ] Want a drop down selection with 'item' and to display 'date' & 'value' in a chart (any chart will do)

Google Charts API says that the ChartWrapper needs to define the data set (see https://developers.google.com/chart/interactive/docs/gallery/controls) // The chart will use the columns 'date' and 'value' // out of all the available ones. 'view': {'columns': [0, 2]}

I have been able to get this to work by editing Dashboards\Wrappers\ChartWrapper.php to hard code the relevant item to the json, overriding jsonSerialize from the parent:

public function jsonSerialize()
{
    return [
        'options'     => $this->contents,
        'containerId' => (string) $this->elementId,
        $this->contents->getWrapType() => $this->contents->getType(),
    'view' => [ 'columns' => [0,2], ],
    ];
}

I think there is additional code required to add a customize function to the Wrapper class (like the Chart class) to support this, unless someone can suggest a different mechanism

am-css commented 3 years ago

I fixed this by allowing Wrapper to extend Customizable, and then this allows setOptions() to be called on the Wrapper With this I can do this $cw = Lava::ChartWrapper($chart, 'chart') ->setOption('view', [ 'columns' => [0,2], ]);

Not sure what the implication of extending Customizable like this is, but it works for me

If I have time I may pull the code, create a branch and submit the changes