In the below example i have 3 series Region 1,2 & 3.. i want these series also to be dyanamic what ive done is used a mysql query using the DISTINCT CLAUSE got all the values of the attribute now depending on how many distinct values i have i ned that many Series. n then the values for these Series again needs an invocation of the Mysql query.
public class StackedBarChartSmple extends Application {
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setScene(new Scene(root));
String[] years = {"2007", "2008", "2009"};
CategoryAxis xAxis = CategoryAxisBuilder.create()
.categories(FXCollections.<String>observableArrayList(years)).build();
NumberAxis yAxis = NumberAxisBuilder.create()
.label("Units Sold")
.lowerBound(0.0d)
.upperBound(10000.0d)
.tickUnit(1000.0d).build();
ObservableList<StackedBarChart.Series> barChartData = FXCollections.observableArrayList(
new StackedBarChart.Series("Region 1", FXCollections.observableArrayList(
new StackedBarChart.Data(years[0], 567d),
new StackedBarChart.Data(years[1], 1292d),
new StackedBarChart.Data(years[2], 1292d)
)),
new StackedBarChart.Series("Region 2", FXCollections.observableArrayList(
new StackedBarChart.Data(years[0], 956),
new StackedBarChart.Data(years[1], 1665),
new StackedBarChart.Data(years[2], 2559)
)),
new StackedBarChart.Series("Region 3", FXCollections.observableArrayList(
new StackedBarChart.Data(years[0], 1154),
new StackedBarChart.Data(years[1], 1927),
new StackedBarChart.Data(years[2], 2774)
))
);
StackedBarChart chart = new StackedBarChart(xAxis, yAxis, barChartData, 25.0d);
root.getChildren().add(chart);
}
@Override public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}
Dynamic Stacked Bar ChartAnanth February 28, 2013 at 9:56 PM
In the below example i have 3 series Region 1,2 & 3.. i want these series also to be dyanamic what ive done is used a mysql query using the DISTINCT CLAUSE got all the values of the attribute now depending on how many distinct values i have i ned that many Series. n then the values for these Series again needs an invocation of the Mysql query. public class StackedBarChartSmple extends Application { private void init(Stage primaryStage) { Group root = new Group(); primaryStage.setScene(new Scene(root)); String[] years = {"2007", "2008", "2009"}; CategoryAxis xAxis = CategoryAxisBuilder.create() .categories(FXCollections.<String>observableArrayList(years)).build(); NumberAxis yAxis = NumberAxisBuilder.create() .label("Units Sold") .lowerBound(0.0d) .upperBound(10000.0d) .tickUnit(1000.0d).build(); ObservableList<StackedBarChart.Series> barChartData = FXCollections.observableArrayList( new StackedBarChart.Series("Region 1", FXCollections.observableArrayList( new StackedBarChart.Data(years[0], 567d), new StackedBarChart.Data(years[1], 1292d), new StackedBarChart.Data(years[2], 1292d) )), new StackedBarChart.Series("Region 2", FXCollections.observableArrayList( new StackedBarChart.Data(years[0], 956), new StackedBarChart.Data(years[1], 1665), new StackedBarChart.Data(years[2], 2559) )), new StackedBarChart.Series("Region 3", FXCollections.observableArrayList( new StackedBarChart.Data(years[0], 1154), new StackedBarChart.Data(years[1], 1927), new StackedBarChart.Data(years[2], 2774) )) ); StackedBarChart chart = new StackedBarChart(xAxis, yAxis, barChartData, 25.0d); root.getChildren().add(chart); } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
Post your Comment