banner



How To Change Background Color In Javafx

  • Selected Reading
  • UPSC IAS Exams Notes
  • Programmer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

How to set a background image to a JavaFX chart?


The javafx.scene.chart package provides classes to create diverse charts namely − line chart, area chart, bar nautical chart, pie nautical chart, chimera chart, scatter chart, etc.

You can create the required chart by instantiating the respective form.

Setting background image and the color

  • The -fx-background-image course of JavaFX CSS is used to gear up an image as a background to a chart.

  • The -fx-background-color (of the region chart-plot-background ) class of JavaFX CSS is used to gear up the back ground color.

  • JavaFX Scene grade has an appreciable listing to hold all the required fashion sheets. You can get this listing using the getStylesheets() method.

To gear up an image every bit a background to a chart −

  • Create a CSS file in the current package of the project sheet (say LineChart.css).

  • Set the groundwork paradigm using the -fx-groundwork-image CSS class as −

.chart-plot-background {    -fx-groundwork-paradigm: url("cat.jpg"); }
  • Prepare the plot colour as transparent using the -fx-background-colour CSS class as −

.chart-plot-background {    -fx-background-color: transparent; }
  • In the plan, get the observable list of style sheets using the getStylesheets() method.

  • Add the created CSS file to the listing using the add() method.

Example

LineChart.CSS −

.nautical chart {    -fx-padding: 10px;    -fx-background-paradigm: url("true cat.jpg"); } .nautical chart-plot-background {    -fx-groundwork-colour: transparent; } .nautical chart-vertical-grid-lines {    -fx-stroke: #dedddc; -fx-stroke-width: 2; } .nautical chart-horizontal-grid-lines {    -fx-stroke: #dedddc; -fx-stroke-width: ii; }

Example.java −

import javafx.awarding.Application; import javafx.scene.Scene; import javafx.scene.chart.BubbleChart; import javafx.stage.Phase; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.layout.StackPane; public class Instance extends Awarding {    public void get-go(Stage stage) {       //Defining the axes       NumberAxis xAxis = new NumberAxis(0, 100, 10);       xAxis.setLabel("Age");       NumberAxis yAxis = new NumberAxis(twenty, 100, 10);       yAxis.setLabel("Weight");       //Creating the Bubble chart       BubbleChart bubbleChart = new BubbleChart(xAxis, yAxis);       //Prepare XYChart.Series objects past setting information       XYChart.Series series = new XYChart.Series();       series.setName("work");       series.getData().add(new XYChart.Data(ten,30,4));       series.getData().add(new XYChart.Information(25,40,v));       series.getData().add together(new XYChart.Data(40,l,9));       series.getData().add together(new XYChart.Data(55,60,7));       series.getData().add(new XYChart.Data(lxx,70,9));       series.getData().add together(new XYChart.Data(85,eighty,6));       //Setting the data to bar nautical chart       bubbleChart.getData().add(series);       //Creating a Grouping object       StackPane root = new StackPane(bubbleChart);       //Setting a scene       Scene scene = new Scene(root, 595, 300);       stage.setTitle("Bubble Chart");       scene.getStylesheets().add("styles/LineChart.css");       stage.setScene(scene);       phase.show();    }    public static void chief(Cord args[]){       launch(args);    } }

Output

raja

Published on xix-May-2020 12:21:24

  • Related Questions & Answers
  • How to set a item color as background to a JavaFX chart?
  • How to set background image of a webpage?
  • How to create a Pie nautical chart using JavaFX?
  • How to create a line nautical chart using JavaFX?
  • How to create a bar chart using JavaFX?
  • How to create a bubble chart using JavaFX?
  • How to create a scatter chart using JavaFX?
  • How to set a background image to be stock-still with JavaScript DOM?
  • How to gear up image as hyperlink in JavaFX?
  • How to create a stacked surface area chart using JavaFX?
  • How to create a stacked bar chart using JavaFX?
  • How to set groundwork image in CSS using jQuery?
  • How to create/salve the epitome of a JavaFX pie chart without actually showing the window?
  • How to set the starting position of a background image in JavaScript DOM?
  • How to create a blurry background epitome with CSS?

How To Change Background Color In Javafx,

Source: https://www.tutorialspoint.com/how-to-set-a-background-image-to-a-javafx-chart

Posted by: reynoldsfoure1965.blogspot.com

0 Response to "How To Change Background Color In Javafx"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel