Wednesday, March 21, 2018

JAVAFX - How fill and work with BarChart (graph)

import javafx.scene.chart.BarChart;
...
@FXML BarChart barChart1;
...
/* set texts */
    
barChart1.setTitle( "This is a chart" );
    
barChart1.getXAxis().setLabel( "x axis" );
barChart1.getYAxis().setLabel( "y axis" );
   
barChart1.setLegendVisible( false );

/* add data */
    
XYChart.Series series1 = new XYChart.Series();    
series1.getData().add( new XYChart.Data( "Q1", 5 ) );
series1.getData().add( new XYChart.Data( "Q2", 5.5 ) );
series1.getData().add( new XYChart.Data( "Q3", 8 ) );
series1.getData().add( new XYChart.Data( "Q4", 3 ) );        
         
barChart1.getData().add( series1 );       
Output:

No comments:

Post a Comment