I am trying to display a JavaFX multi-line chart. I try to open this graph on a Jbutton click from another Jframe and pass a data array to the graph class.
How can I make this class into an object and have it show the graph when the Jbutton is clicked from another Jfame?
This is my edited code and two arrays showing temporary data.
import javafx.application.Application;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class LineGrph extends Application {
@Override
public void start(Stage stage) {
double LE[] = {23.5,12.0,44.0,12.6,8.5,4.6,53.6}; // this two arrays should pass from another Jframe
double RE[] = {22.5,32.0,40.0,32.6,43.5,23.6,11.6};
stage.setTitle("Line Chart Sample");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Hz");
yAxis.setLabel("DB");
xAxis.setSide(Side.TOP);
final LineChart<String,Number> lineChart =
new LineChart<String,Number>(xAxis,yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
XYChart.Series series1 = new XYChart.Series();
series1.setName("Portfolio 1");
int count = 125;
for (int i = 0; i<= 6 ; i++)
{
String x = Integer.toString(count);
series1.getData().add(new XYChart.Data(x, LE[i]));
count = count * 2;
}
XYChart.Series series2 = new XYChart.Series();
series2.setName("Portfolio 2");
int count2 = 125;
for (int p = 0; p<= 6 ; p++)
{
String x = Integer.toString(count2);
series2.getData().add(new XYChart.Data(x, RE[p]));
count2 = count2 * 2;
}
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().addAll(series1, series2);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}