Created
June 16, 2021 13:11
-
-
Save Da9el00/9383302e5c04867c0d5f0c878e85b1fa to your computer and use it in GitHub Desktop.
JavaFX LineChar design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
import javafx.fxml.Initializable; | |
import javafx.scene.chart.LineChart; | |
import javafx.scene.chart.XYChart; | |
import javafx.scene.layout.AnchorPane; | |
import javafx.stage.Stage; | |
import java.net.URL; | |
import java.util.ResourceBundle; | |
public class Controller implements Initializable { | |
private double x = 0,y = 0; | |
@FXML | |
private LineChart<?, ?> lineChart; | |
@FXML | |
private AnchorPane sideBar; | |
private Stage stage; | |
@Override | |
public void initialize(URL url, ResourceBundle resourceBundle) { | |
sideBar.setOnMousePressed(mouseEvent -> { | |
x = mouseEvent.getSceneX(); | |
y = mouseEvent.getSceneY(); | |
}); | |
sideBar.setOnMouseDragged(mouseEvent -> { | |
stage.setX(mouseEvent.getScreenX() - x); | |
stage.setY(mouseEvent.getScreenY() - y); | |
}); | |
lineChart.getXAxis().setLabel("XAxis"); | |
lineChart.getYAxis().setLabel("YAxis"); | |
XYChart.Series series1 = new XYChart.Series(); | |
series1.getData().add(new XYChart.Data("1",5)); | |
series1.getData().add(new XYChart.Data("2",4)); | |
series1.getData().add(new XYChart.Data("3",6)); | |
series1.getData().add(new XYChart.Data("5",3)); | |
series1.getData().add(new XYChart.Data("9",10)); | |
XYChart.Series series2 = new XYChart.Series(); | |
series2.getData().add(new XYChart.Data("1",2)); | |
series2.getData().add(new XYChart.Data("3",2)); | |
series2.getData().add(new XYChart.Data("4",5)); | |
XYChart.Series series3 = new XYChart.Series(); | |
series3.getData().add(new XYChart.Data("1",1)); | |
series3.getData().add(new XYChart.Data("2",4)); | |
series3.getData().add(new XYChart.Data("4",9)); | |
lineChart.getData().addAll(series1,series2,series3); | |
} | |
public void setStage(Stage stage){ | |
this.stage = stage; | |
} | |
@FXML | |
void closeProgram(ActionEvent event) { | |
stage.close(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
import javafx.scene.paint.Color; | |
import javafx.stage.Stage; | |
import javafx.stage.StageStyle; | |
public class Main extends Application { | |
@Override | |
public void start(Stage primaryStage) throws Exception{ | |
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml")); | |
Parent root = loader.load(); | |
Controller controller = loader.getController(); | |
Scene scene = new Scene(root); | |
scene.setFill(Color.TRANSPARENT); | |
primaryStage.initStyle(StageStyle.TRANSPARENT); | |
primaryStage.setScene(scene); | |
controller.setStage(primaryStage); | |
primaryStage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.chart.CategoryAxis?> | |
<?import javafx.scene.chart.LineChart?> | |
<?import javafx.scene.chart.NumberAxis?> | |
<?import javafx.scene.control.Button?> | |
<?import javafx.scene.layout.AnchorPane?> | |
<?import javafx.scene.layout.VBox?> | |
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: transparent;" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"> | |
<children> | |
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" styleClass="background" stylesheets="@style.css"> | |
<children> | |
<AnchorPane fx:id="sideBar" prefHeight="35.0" prefWidth="600.0" styleClass="topBar" stylesheets="@style.css"> | |
<children> | |
<Button layoutX="548.0" layoutY="5.0" mnemonicParsing="false" onAction="#closeProgram" prefHeight="25.0" prefWidth="0.0" styleClass="closeButton" stylesheets="@style.css" text="X" textFill="WHITE" /> | |
</children></AnchorPane> | |
<LineChart fx:id="lineChart" createSymbols="false" layoutX="14.0" layoutY="66.0" prefHeight="334.0" prefWidth="525.0" stylesheets="@style.css"> | |
<xAxis> | |
<CategoryAxis side="BOTTOM" /> | |
</xAxis> | |
<yAxis> | |
<NumberAxis side="LEFT" /> | |
</yAxis> | |
</LineChart> | |
</children> | |
</AnchorPane> | |
</children> | |
</VBox> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.invisibleBox{ | |
-fx-background-color: transparent; | |
} | |
.topBar{ | |
-fx-background-radius: 25 25 0 0; | |
-fx-background-color: #0b3048; | |
} | |
.background{ | |
-fx-background-color: #05263b; | |
-fx-background-radius: 25; | |
} | |
.closeButton{ | |
-fx-background-color:#0b3048; | |
} | |
.closeButton:hover{ | |
-fx-background-color: #e94e50; | |
} | |
.chart{ | |
-fx-background-color: #05263b; | |
-fx-font-size: 20; | |
-fx-text-fill: white; | |
-fx-legend-visible: false; | |
} | |
.axis-label { | |
-fx-text-fill: #ffffff; | |
} | |
.chart-plot-background { | |
-fx-background-color:transparent; | |
} | |
.default-color0.chart-series-line { -fx-stroke: #238591; } | |
.default-color1.chart-series-line { -fx-stroke: #e5d849; } | |
.default-color2.chart-series-line { -fx-stroke: #ed4d51; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment