java - How to put multiple LineCharts into one Scene/Stage? -
i looking way put 3 linecharts single window. mean want have them next each other, or 1 under another.
i searching way wasn't able find anything. tried search how put multiple scenes 1 stage... how put multiple linecharts 1 scene... etc... without success.
this code:
private void drawgraph(stage stage, double[] axisvalues) { //defining axes final numberaxis xaxis = new numberaxis(); final numberaxis yaxis = new numberaxis(); xaxis.setlabel("time"); //creating chart final linechart<number,number> linechart = new linechart<number,number>(xaxis,yaxis); linechart.settitle("axis' values"); //defining series xychart.series series = new xychart.series(); series.setname("x axis"); //populating series data (int = 1; i<33; i++){ series.getdata().add(new xychart.data(i, axisvalues[i])); } //scene scene = new scene(linechart,800,600); scene scene = new scene(linechart,800,600); linechart.getdata().add(series); stage.setscene(scene); stage.show(); }
problem
there 1 scene in 1 stage (window), not able add more 1 scene same stage. able change scene of stage.

solution
in scene builder able see possible solution in preview. add 3 linecharts flowpane, , after that, add flowpane scene.

there type safety problems in code, created whole example show how it.
import javafx.application.application; import javafx.scene.scene; import javafx.scene.chart.linechart; import javafx.scene.chart.numberaxis; import javafx.scene.chart.xychart; import javafx.scene.layout.flowpane; import javafx.stage.stage; public class flowchart extends application { @override public void start(stage primarystage) { double[] data = {0.1, 0.4, 0.5, 0.7, 0.9, 1.0}; linechart<number, number> lc = createlinechart(data); linechart<number, number> lc1 = createlinechart(data); linechart<number, number> lc2 = createlinechart(data); flowpane root = new flowpane(); root.getchildren().addall(lc, lc1, lc2); scene scene = new scene(root, 800, 600); primarystage.settitle("hello world!"); primarystage.setscene(scene); primarystage.show(); } /** * @param args command line arguments */ public static void main(string[] args) { launch(args); } private linechart<number, number> createlinechart(double[] axisvalues) { //defining axes final numberaxis xaxis = new numberaxis(); final numberaxis yaxis = new numberaxis(); xaxis.setlabel("time"); //creating chart final linechart<number, number> linechart = new linechart<>(xaxis, yaxis); linechart.settitle("axis' values"); //defining series xychart.series<number, number> series = new linechart.series<>(); series.setname("x axis"); //populating series data (int = 0; < axisvalues.length; i++) { xychart.data<number, number> data = new linechart.data<>(i, axisvalues[i]); series.getdata().add(data); } linechart.getdata().add(series); return linechart; } } result

Comments
Post a Comment