мой первый ответ на stackoverflow (аааа ^^ ')
для реализации PCA см. Здесь: Реализация PCA в Java
для удобного построения любого введите Java Я рекомендую JavaFX (https://openjfx.io/)
. Вот пример кода для создания графиков с использованием JavaFX:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.Stage;
/*
* DIFFERENT CHART TYPES IN JAVA FX:
*
* JavaFX PieChart
JavaFX LineChart
JavaFX Area Chart
JavaFX BubbleChart
JavaFX BarChart
JavaFX ScatterChart
*
*/
public class MyCharts extends Application {
private double screenFac = 1.25;
private Rectangle2D screenSize;
private double width;
private double height;
private Pane root;
private Parent showMyCharts() {
root = createRoot();
/* we have to use NEW NumberAxis-Objects
* for each BarChart
* it is not possible to share the same NumberAxis-Object
* with different Bar charts
*/
final NumberAxis xAxis1 = new NumberAxis();
final NumberAxis xAxis2 = new NumberAxis();
final NumberAxis xAxis3 = new NumberAxis();
final CategoryAxis yAxis1 = new CategoryAxis();
final CategoryAxis yAxis2 = new CategoryAxis();
final CategoryAxis yAxis3 = new CategoryAxis();
final BarChart<Number, String> bc1 = new BarChart<Number, String>(xAxis1, yAxis1);
// here use other NumberAxis-Object
// final BarChart<Number, String> bc2 = new BarChart<Number, String>(xAxis2, yAxis2);
LineChart<Number, String> l1 = new LineChart<>(xAxis2, yAxis2);
// define BarChart settings
bc1.setTitle("myBarChart");
xAxis1.setLabel("Value");
xAxis1.setTickLabelRotation(90);
yAxis1.setLabel("Item");
l1.setTitle("myLineChart");
xAxis2.setLabel("Value");
// create some Data series
XYChart.Series<Number, String> series1 = new XYChart.Series<>();
final String itemA = "A";
final String itemB = "B";
final String itemC = "F";
series1.setName("2005");
series1.getData().add(new XYChart.Data<Number, String>(45.0D, itemA));
series1.getData().add(new XYChart.Data<Number, String>(55.0D, itemB));
series1.getData().add(new XYChart.Data<Number, String>(75.0D, itemC));
// series1.getData().add(new XYChart.Data(44, itemB));
// series1.getData().add(new XYChart.Data(18, itemC));
bc1.getData().add(series1);
// also XYChart.Series cannot be shared; we have to create a new Object for the line chart
XYChart.Series<Number, String> series2 = new XYChart.Series<>();
series2.setName("2005");
series2.getData().add(new XYChart.Data<Number, String>(45.0D, itemA));
series2.getData().add(new XYChart.Data<Number, String>(55.0D, itemB));
series2.getData().add(new XYChart.Data<Number, String>(75.0D, itemC));
l1.getData().add(series2);
/* piechart seems to be a bit special; you cann add the observeabel list directly if you create
* the piechart or you have to create PieChart.Data(..) if you want to add the data after creating the piechart-object
*/
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Grapefruit", 13),
new PieChart.Data("Oranges", 25),
new PieChart.Data("Plums", 10),
new PieChart.Data("Pears", 22),
new PieChart.Data("Apples", 30));
PieChart p2 = new PieChart(pieChartData);
PieChart p1 = new PieChart();
PieChart.Data slice1 = new PieChart.Data("Desktop", 213);
PieChart.Data slice2 = new PieChart.Data("Phone" , 67);
PieChart.Data slice3 = new PieChart.Data("Tablet" , 36);
p1.getData().add(slice1);
p1.getData().add(slice2);
p1.getData().add(slice3);
HBox hbox = new HBox();
VBox vBox1 = new VBox();
VBox vBox2 = new VBox();
vBox1.getChildren().addAll(l1, bc1);
vBox2.getChildren().addAll(p1, p2);
hbox.getChildren().addAll(vBox1, vBox2);
// bc.getData().addAll(series1, series2, series3);
// XYChart<>.Series series1 = new XYChart.Series();
// series1.setName("2003");
// series1.getData().add(new XYChart.Data(2, itemA));
// series1.getData().add(new XYChart.Data(20, itemB));
// series1.getData().add(new XYChart.Data(10, itemC));
//
root.getChildren().add(hbox);
return root;
}
private Pane createRoot() {
screenSize = Screen.getPrimary().getBounds();
width = screenSize.getWidth();
height = screenSize.getHeight();
root = new Pane(); // Pane is a layout without any grid o.s.e.
root.setPrefSize(width / screenFac, height / screenFac);
return root;
}
@Override
public void start(Stage stage) throws Exception {
Scene scene = new Scene(showMyCharts());
stage.setScene(scene);
stage.show();
}
public static void main(String[] charts) {
launch(charts);
}
}