xdev-software / chartjs-java-model

Provides Java models for Chart.js
Apache License 2.0
11 stars 6 forks source link

Datasets: make less strict #239

Closed jepsar closed 3 weeks ago

jepsar commented 3 weeks ago

Checklist

Description

Currently you can only BarDatasets to BarData. I'm in the process of migrating a project's PrimeFaces 13 data models to XDev data models. There we had a chart with stacked bars and a single line showing the totals. We did it like:

  public void addTotalsLineToBar(final String label) {
    final LineChartDataSet dataSet = new LineChartDataSet();
    final String color = ColorUtils.hslaDark(label);
    dataSet.setData(new ArrayList<>(ChartModels.getTotalsPerLabel(barChart)));
    dataSet.setFill(false);
    dataSet.setLabel(label);
    dataSet.setBackgroundColor(color);
    dataSet.setBorderColor(color);
    dataSet.setTension(0.2);
    barChart.getData().getDataSet().add(0, dataSet);
  }

This is with the old PrimeFaces data model which did allow you to add other types of datasets to bar data. Would be great if the XDev model would allow that as well.

Additional information

No response

AB-xdev commented 3 weeks ago

Thank you for the issue.

We already implemented support for mixed charts with #128

Here is an example from our tests: https://github.com/xdev-software/chartjs-java-model/blob/136e904b145a257eda94634291b1d93252234ad5/chartjs-java-model/src/test/java/software/xdev/chartjs/model/BasicChartTest.java#L140-L153 https://github.com/xdev-software/chartjs-java-model/blob/develop/chartjs-java-model/src/test/resources/screenshotReferences/MixedChartBasic.png

Hope this help :)

jepsar commented 3 weeks ago

Awesome! I'll try it like that!