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

Support Scatter Line Charts #4

Closed
moberwasserlechner opened this issue Jul 8, 2016 · 1 comment
Closed

Support Scatter Line Charts #4

moberwasserlechner opened this issue Jul 8, 2016 · 1 comment
Milestone

Comments

@moberwasserlechner
Copy link
Owner

Configuring this variant of a line chart is not supported in the initial release.

http://www.chartjs.org/docs/#line-chart-scatter-line-charts

@moberwasserlechner
Copy link
Owner Author

moberwasserlechner commented Jul 24, 2016

Example usage:

  ScatterChartConfig config = new ScatterChartConfig();
        config
            .data()
                .addDataset(new ScatterDataset().label("My First dataset").xAxisID("x-axis-1").yAxisID("y-axis-1"))
                .addDataset(new ScatterDataset().label("My Second  dataset").xAxisID("x-axis-1").yAxisID("y-axis-2"))
                .and();
        config.
            options()
                .responsive(true)
                .hover()
                    .mode(Mode.SINGLE)
                    .and()
                .title()
                    .display(true)
                    .text("Chart.js Scatter Chart - Multi Axis")
                    .and()
                .scales()
                    .add(Axis.X, new LinearScale().position(Position.BOTTOM).gridLines().zeroLineColor("rgba(0,0,0,1)").and())
                    .add(Axis.Y, new LinearScale().display(true).position(Position.LEFT).id("y-axis-1"))
                    .add(Axis.Y, new LinearScale().display(true).position(Position.RIGHT).id("y-axis-2").ticks().reverse(true).and().gridLines().drawOnChartArea(false).and())
                    .and()
               .done();

        for (Dataset<?, ?> ds : config.data().getDatasets()) {
            ScatterDataset lds = (ScatterDataset) ds;
            lds.borderColor(randomColor(.4));
            lds.backgroundColor(randomColor(.1));
            lds.pointBorderColor(randomColor(.7));
            lds.pointBackgroundColor(randomColor(.5));
            lds.pointBorderWidth(1);
            for (int i = 0; i < 7; i++) {
                lds.addData(randomScalingFactor(), randomScalingFactor());
            }
        }

        ChartJs lineChart = new ChartJs(config);
        lineChart.setJsLoggingEnabled(true);
        lineChart.setWidth(50, Unit.PERCENTAGE);

        lineChart.addClickListener((a,b) -> {
            ScatterDataset dataset = (ScatterDataset) config.data().getDatasets().get(a);
            Notification.show("ScatterDataset at idx:" + a + "; Data: idx=" + b + "; Value=" + dataset.getData().get(b), Type.TRAY_NOTIFICATION);
        });
        return lineChart; 

Produces:

image

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

No branches or pull requests

1 participant