java - How to perform big numbers on axis (for example, 10^3 format) in chart? -
using big space performing long numbers not decision. if have graph medium scale 50 000, on y axis written "50 000, 60 000, 10 000". can perform there 50 * 10^3 or else? it's necessary charts several scales here
use ticklabelformatter
on axis. example:
numberformat format = new decimalformat("#.#e0"); yaxis.setticklabelformatter(new stringconverter<number>() { @override public string tostring(number number) { return format.format(number.doublevalue()); } @override public number fromstring(string string) { try { return format.parse(string); } catch (parseexception e) { e.printstacktrace(); return 0 ; } } });
complete example:
import java.text.decimalformat; import java.text.numberformat; import java.text.parseexception; import javafx.application.application; import javafx.scene.scene; import javafx.scene.chart.linechart; import javafx.scene.chart.numberaxis; import javafx.scene.chart.xychart; import javafx.stage.stage; import javafx.util.stringconverter; public class linechartwithformattednumbers extends application { @override public void start(stage primarystage) { final numberaxis xaxis = new numberaxis(); final numberaxis yaxis = new numberaxis(); numberformat format = new decimalformat("#.#e0"); yaxis.setticklabelformatter(new stringconverter<number>() { @override public string tostring(number number) { return format.format(number.doublevalue()); } @override public number fromstring(string string) { try { return format.parse(string); } catch (parseexception e) { e.printstacktrace(); return 0 ; } } }); xaxis.setlabel("number of month"); //creating chart final linechart<number,number> linechart = new linechart<number,number>(xaxis,yaxis); linechart.settitle("stock monitoring, 2010"); //defining series xychart.series<number, number> series = new xychart.series<>(); series.setname("my portfolio"); //populating series data series.getdata().add(new xychart.data<>(1, 23e10)); series.getdata().add(new xychart.data<>(2, 14e9)); series.getdata().add(new xychart.data<>(3, 15e10)); series.getdata().add(new xychart.data<>(4, 24e9)); series.getdata().add(new xychart.data<>(5, 34e10)); series.getdata().add(new xychart.data<>(6, 36e10)); series.getdata().add(new xychart.data<>(7, 22e10)); series.getdata().add(new xychart.data<>(8, 45e10)); series.getdata().add(new xychart.data<>(9, 43e10)); series.getdata().add(new xychart.data<>(10, 17e10)); series.getdata().add(new xychart.data<>(11, 29e10)); series.getdata().add(new xychart.data<>(12, 25e10)); scene scene = new scene(linechart,800,600); linechart.getdata().add(series); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } }
Comments
Post a Comment