asantibanez / livewire-charts

Neat Livewire Charts for your Laravel projects
MIT License
787 stars 116 forks source link

MultipleColumn somehow grouping results wrongly #88

Open djowebdev opened 1 year ago

djowebdev commented 1 year ago

Describe the bug When I create a multiple column graph, it seems to group non-existing values and display them wrongly into the previous column. Basically it does not consider empty or non-existing entries for the group.

Picture:

image

Data:

... ->addSeriesColumn('Peter', '2022-02-27', 20) ->addSeriesColumn('Peter', '2022-02-28', 40) ->addSeriesColumn('Harry', '2022-02-26', 15) ->addSeriesColumn('Harry', '2022-03-02', 35) ->addSeriesColumn('Sarah', '2022-02-02', 15) ->addSeriesColumn('Sarah', '2022-03-02', 35) ...

To Reproduce Steps to reproduce the behavior:

Component: public function render() { $multiColumnChartModel = (new ColumnChartModel()) ->setTitle('Expenses by Name') ->multiColumn() ->addSeriesColumn('Peter', '2022-02-27', 20) ->addSeriesColumn('Peter', '2022-02-28', 40) ->addSeriesColumn('Harry', '2022-02-26', 15) ->addSeriesColumn('Harry', '2022-03-02', 35) ->addSeriesColumn('Sarah', '2022-02-02', 15) ->addSeriesColumn('Sarah', '2022-03-02', 35) ; return view('livewire.statistics-component') ->with([ 'multiColumnChartModel' => $multiColumnChartModel, ]); }

View: <livewire:livewire-column-chart key="{{ $multiColumnChartModel->reactiveKey() }}" :column-chart-model="$multiColumnChartModel" />

Expected behavior I would expect all the dates to be on the X-axis, even if there is no entry for the person.

Here is a mockup of what I would expect:

image

rhnkyr commented 1 year ago

Hi @djowebdev. Do you have any solution for this one?

djowebdev commented 1 year ago

Hi @djowebdev. Do you have any solution for this one?

Unfortunately no a perfect one. The workaround is to create 0-entries for the other dates, actually this is what I did for the mockup (just add "0-entries" via addSeriesColumn('Name', '2022-xx-xx', 0)). So the data preparation is not done by livewire-charts it seems.

It is tedious but potentially a nice-to-have thing and not a bug?! Not sure what the developers think

vekkon commented 3 months ago

What about just changing up the name values with the date values? Works for me..