Table of Contents
import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Application; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; import javafx.scene.web.WebEngine; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.scene.web.WebView; import javafx.stage.Stage;
public class Fusioncharts_javafx extends Application {
@Override
public void start(Stage stage) throws Exception {
WebView myWebView = new WebView();
final WebEngine engine = myWebView.getEngine();
Button btn1 = new Button("Render Chart from file");
btn1.setOnAction(new EventHandler < ActionEvent > () {
@Override
public void handle(ActionEvent event) {
File currDir = new File(".");
String path = currDir.getAbsolutePath();
path = path.substring(0, path.length() - 1);
path = path.replaceAll("\\\\", "/");
// System.out.println(path);
File file = new File(path + "/src/fusioncharts_javafx/index.html");
URL url;
try {
url = file.toURI().toURL();
engine.load(url.toString());
} catch (MalformedURLException ex) {
Logger.getLogger(Fusioncharts_javafx.class.getName()).log(Level.SEVERE, null, ex);
}
// file:/C:/test/a.html
}
});
<html>
<head>
<title>My first chart using FusionCharts Suite XT</title>
<script type="text/javascript" src="fusioncharts.js"></script>
<script type="text/javascript" src="fusioncharts.charts.js"></script>
<script type="text/javascript">
FusionCharts.ready(function() {
var revenueChart = new FusionCharts({
type: 'column2d',
renderAt: 'chartContainer',
width: '550',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenues (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14"
},
"data": [{
"label": "Jan",
"value": "420000"
},
{
"label": "Feb",
"value": "810000"
},
{
"label": "Mar",
"value": "720000"
},
{
"label": "Apr",
"value": "550000"
},
{
"label": "May",
"value": "910000"
},
{
"label": "Jun",
"value": "510000"
},
{
"label": "Jul",
"value": "680000"
},
{
"label": "Aug",
"value": "620000"
},
{
"label": "Sep",
"value": "610000"
},
{
"label": "Oct",
"value": "490000"
},
{
"label": "Nov",
"value": "900000"
},
{
"label": "Dec",
"value": "730000"
}
],
"trendlines": [{
"line": [{
"startvalue": "700000",
"color": "#1aaf5d",
"valueOnRight": "1",
"displayvalue": "Monthly Target"
}]
}]
}
}).render();
});
</script>
</head>
<body>
<div id="chartContainer">FusionCharts XT will load here! </div>
<div>Loaded from a file</div>
</body>
</html>
Button btn2 = new Button("Render Chart from static string");
btn2.setOnAction(new EventHandler () {
@Override
public void handle(ActionEvent event) {
engine.loadContent("\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
" FusionCharts XT will load here!\n" +
" Loaded from a string \n" +
"\n" +
"");
}
});
VBox root = new VBox();
root.getChildren().addAll(myWebView, btn1, btn2);
Scene scene = new Scene(root, 700, 510);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/ public static void main(String[] args) {
launch(args);
}
}
The full java code for the sample looks as under:
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.scene.web.WebEngine;
import javafx.scene.layout.VBox;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Fusioncharts_javafx extends Application {
@Override
public void start(Stage stage) throws Exception {
WebView myWebView = new WebView();
final WebEngine engine = myWebView.getEngine();
Button btn1 = new Button("Render Chart from file");
btn1.setOnAction(new EventHandler () {
@Override
public void handle(ActionEvent event) {
File currDir = new File(".");
String path = currDir.getAbsolutePath();
path = path.substring(0, path.length() - 1);
path = path.replaceAll("\\\\", "/");
// System.out.println(path);
File file = new File(path + "/src/fusioncharts_javafx/index.html");
URL url;
try {
url = file.toURI().toURL();
engine.load(url.toString());
} catch (MalformedURLException ex) {
Logger.getLogger(Fusioncharts_javafx.class.getName()).log(Level.SEVERE, null, ex);
}
// file:/C:/test/a.html
}
});
Button btn2 = new Button("Render Chart from static string");
btn2.setOnAction(new EventHandler () {
@Override
public void handle(ActionEvent event) {
engine.loadContent("\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
" FusionCharts XT will load here!\n" +
" Loaded from a string \n" +
"\n" +
"");
}
});
VBox root = new VBox();
root.getChildren().addAll(myWebView, btn1, btn2);
Scene scene = new Scene(root, 700, 510);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/ public static void main(String[] args) {
launch(args);
}
}
To create pie charts and generate statistical data, you’ll find this list of the best…
To implement FusionCharts in a dynamically resizing flexbox layout, ensure that the chart's dimensions are…
At FusionCharts, we believe in empowering developers and businesses with cutting-edge data visualization tools that…
Ever had a data set that seemed more complicated than a Rubik's cube? You’re not…
We’ve all seen them in textbooks or presentations—those overlapping circles that simplify complex information into…
We’re excited to announce the upcoming release of FusionCharts v4.1—a groundbreaking step forward in the…