0

I need help to combine XYModel and BoxPlotModel into a single Chart

asked 2020-09-25 14:10:12 +0800

bztom35 gravatar image bztom35
103 4

updated 2020-09-25 14:11:16 +0800

I am trying to combine the two different series into a single chart. Is there a way to do it?

All my dataset are coming directly from a database.

Normally, I can just set chart.setModel(getData.getXYModel), but Series does not support setModel function.

       Series  ensembleSeries =  new Series();
       ensembleSeries.setType("spline");
       ensembleSeries.setData(getData.getXYModel()); <-- Error here: does not support setModel()

       Series boxplotSeries = new Series();
       boxplotSeries.setType("boxplot");
       boxplotSeries.setData(getData.getBoxplotModel()); <-- error here: does not support setModel()

      chart.addSeries(ensembleSeries);
      chart.addSeries(boxplotSeries);

Thanks for any info.

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted
1

answered 2020-09-28 12:15:35 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2020-09-28 12:16:41 +0800

The different ChartModels are only useful to manage a chart with the same series. For charts with different series you have to add the Point objects directly.

The setData method has several overloaded versions. In the example below I used setData(Point... data)

    ...
    chart.setTitle("boxplot with datetime axis");
    chart.getXAxis().setType("datetime");

    Series ensembleSeries = new Series();
    ensembleSeries.setType("spline");
    ensembleSeries.setData(splineData());

    Series boxPlotSeries = new Series();
    boxPlotSeries.setType("boxplot");
    boxPlotSeries.setData(boxplotData());

    chart.addSeries(ensembleSeries);
    chart.addSeries(boxPlotSeries);
    ...

    private Point[] splineData() {
        Point[] data = new Point[5];
        data[0] = new Point(date(-8), 35);
        data[1] = new Point(date(-4), 34);
        data[2] = new Point(date(0), 30);
        data[3] = new Point(date(2), 25);
        data[4] = new Point(date(4), 15);
        return data;
    }

    private Point[] boxplotData() {
        Point[] data = new Point[6];
        data[0] = boxPlotPoint(date(-8), 12, 22, 35, 48, 56);
        data[1] = boxPlotPoint(date(-5), 12, 22, 35, 48, 56);
        data[2] = boxPlotPoint(date(-3), 12, 22, 35, 48, 56);
        data[3] = boxPlotPoint(date(-2), 12, 22, 35, 48, 56);
        data[4] = boxPlotPoint(date(-1), 13, 23, 37, 41, 43);
        data[5] = boxPlotPoint(date(0), 10, 20, 30, 40, 50);
        return data;
    }

    private Point boxPlotPoint(Number datetime, 
            Number low, Number q1, Number med, Number q3, Number high) {
        Point p = new Point();
        p.setX(datetime);
        p.setHigh(low);
        p.setQ1(q1);
        p.setMedian(med);
        p.setQ3(q3);
        p.setLow(high);
        return p;
    }

    private long date(int dayOffset) {
        return LocalDateTime.now().plusDays(dayOffset).toInstant(ZoneOffset.UTC).toEpochMilli();
    }
}

image description

link publish delete flag offensive edit

Comments

Thank you and I will check it out.

bztom35 ( 2020-09-28 23:12:04 +0800 )edit
1

answered 2020-09-28 12:24:29 +0800

cor3000 gravatar image cor3000
6280 2 7

minor low-high-mix-up in the code above (should be):

p.setX(datetime);
p.setLow(low);
p.setQ1(q1);
p.setMedian(med);
p.setQ3(q3);
p.setHigh(high);
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-09-25 14:10:12 +0800

Seen: 9 times

Last updated: Sep 28 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More