protected Component getChart() { final Chart chart = new Chart(); chart.setWidth("500px"); final Configuration configuration = new Configuration(); configuration.getChart().setType(ChartType.GAUGE); configuration.getChart().setAlignTicks(false); configuration.getChart().setPlotBackgroundColor(null); configuration.getChart().setPlotBackgroundImage(null); configuration.getChart().setPlotBorderWidth(0); configuration.getChart().setPlotShadow(false); configuration.setTitle("Temperature"); configuration.getPane().setStartAngle(-150); configuration.getPane().setEndAngle(150); YAxis yAxis = new YAxis(); yAxis.setMin(-30); yAxis.setMax(50); yAxis.setLineColor(new SolidColor("#339")); yAxis.setTickColor(new SolidColor("#339")); yAxis.setMinorTickColor(new SolidColor("#339")); yAxis.setOffset(-25); yAxis.setLineWidth(2); yAxis.setLabels(new Labels()); yAxis.getLabels().setDistance(-20); yAxis.getLabels().setRotationPerpendicular(); yAxis.setTickLength(5); yAxis.setMinorTickLength(5); yAxis.setEndOnTick(false); configuration.addyAxis(yAxis); final ListSeries series = new ListSeries("Temperature", 12); PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge(); plotOptionsGauge.setDataLabels(new Labels()); plotOptionsGauge.getDataLabels().setFormatter("function() {return '' + this.y + ' °C';}"); GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1); gradient.addColorStop(0, new SolidColor("#DDD")); gradient.addColorStop(1, new SolidColor("#FFF")); plotOptionsGauge.getDataLabels().setBackgroundColor(gradient); plotOptionsGauge.getTooltip().setValueSuffix(" °C"); series.setPlotOptions(plotOptionsGauge); configuration.setSeries(series); chart.drawChart(configuration); return chart; }
@Override public void run() { try { while (true) { // Update the data for a while Thread.sleep(10000); if (!lastPushed.equals(lastMessage)) { access( () -> chart .getConfiguration() .getSeries() .forEach( s -> { Double newValue = Double.valueOf(lastMessage.split(":")[3]); ((ListSeries) s).updatePoint(0, newValue); })); System.out.println("pushed -> lastMessage = " + lastMessage); lastPushed = lastMessage; } } } catch (InterruptedException e) { e.printStackTrace(); } }
@Override protected Component getChart() { Chart chart = new Chart(ChartType.LINE); Configuration conf = chart.getConfiguration(); conf.getChart().setPolar(true); conf.setTitle("Budget vs spending"); conf.getTitle().setX(-80); Pane pane = new Pane(); pane.setSize(80, Unit.PERCENTAGE); conf.addPane(pane); XAxis axis = new XAxis(); axis.setCategories( "Sales", "Marketing", "Development", "Customer Support", "Information Technology", "Administration"); axis.setTickmarkPlacement(TickmarkPlacement.ON); axis.setLineWidth(0); YAxis yaxs = new YAxis(); yaxs.setGridLineInterpolation("polygon"); yaxs.setMin(0); yaxs.setLineWidth(0); conf.addxAxis(axis); conf.addyAxis(yaxs); conf.getTooltip().setShared(true); conf.getTooltip().setValuePrefix("$"); conf.getLegend().setAlign(HorizontalAlign.RIGHT); conf.getLegend().setVerticalAlign(VerticalAlign.TOP); conf.getLegend().setY(100); conf.getLegend().setLayout(LayoutDirection.VERTICAL); ListSeries line1 = new ListSeries(43000, 19000, 60000, 35000, 17000, 10000); ListSeries line2 = new ListSeries(50000, 39000, 42000, 31000, 26000, 14000); PlotOptionsLine plotOptions = new PlotOptionsLine(); plotOptions.setPointPlacement(PointPlacement.ON); line1.setPlotOptions(plotOptions); line1.setName("Allocated Budget"); plotOptions = new PlotOptionsLine(); plotOptions.setPointPlacement(PointPlacement.ON); line2.setPlotOptions(plotOptions); line2.setName("Actual Spending"); conf.setSeries(line1, line2); chart.drawChart(conf); return chart; }
private void cargarChart() { ListSeries ls = new ListSeries(); ls.setName("Tokyo"); ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6); getConfiguration().addSeries(ls); }