Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Reload configuration no change values #68

Open
luisrafaelinf opened this issue Jan 25, 2018 · 0 comments
Open

Reload configuration no change values #68

luisrafaelinf opened this issue Jan 25, 2018 · 0 comments

Comments

@luisrafaelinf
Copy link

I try to dynamically change the values ​​of the configuration such as the title and nothing happens. only the first time. I am using thread for reload the charts.

private synchronized void configurarPieChart(String titulo, ChartJs chart, List<ConteoDatos> conteo) {

        PieChartConfig config = (PieChartConfig) chart.getConfig();
        
        if (!Objects.isNull(config.data().getDatasets())) {
            config.data().getDatasets().clear();
        }
        
        config
                .data()
                .labelsAsList(conteo.stream().map(c -> WordUtils.capitalizeFully(c.getDescripcion() )).collect(Collectors.toList()))
                .addDataset(new PieDataset().label("Dataset 1"))
                .and();

        config.
            options()
                .responsive(true)
                .title()
                    .display(true)
                    .text(titulo)
                    .fontColor("#272c33")
                    .fullWidth(true)
                .and()
                .animation()
                    .animateScale(true)
                .   animateRotate(true)
                .and()
                .legend()
                    .display(true)
                    .position(Position.RIGHT)
                    .labels()
                        .fontSize(10)
                        .boxWidth(10)
                        .padding(15)
                    .and()
                .and()
                .done();

        Dataset<?, ?> ds = config.data().getDatasets().get(0);
        PieDataset lds = (PieDataset) ds;

        Double total = conteo.stream()
                .map(c -> new BigDecimal(c.getCantidad()))
                .collect(Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
                .setScale(2, RoundingMode.HALF_UP)
                .doubleValue();

        List<Double> porcentaje = new ArrayList<>();
        List<String> colors = new ArrayList<>();

        conteo.forEach(c -> {
            porcentaje.add(
                    new BigDecimal((c.getCantidad() * 100) / total)
                            .setScale(2, RoundingMode.HALF_UP)
                            .doubleValue()
            );

            colors.add(ColorUtils.randomColor(0.7));

        });
        lds.dataAsList(porcentaje);
        lds.backgroundColor(colors.toArray(new String[colors.size()]));
        chart.refreshData();

    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant