List of usage examples for java.text NumberFormat getInstance
public static final NumberFormat getInstance()
From source file:app.RunApp.java
/** * Create Chart//from w w w . j a v a 2 s . c o m * * @param jpanel Panel * @param type Chart type * @param titleX Title for X axis * @param titleY Title for Y axis * @param showXAxis Indicates if shows X axis * @param chartTitle Chart title * @return ChartPanel with the generated chart */ private ChartPanel createJChart(JPanel jpanel, String type, String titleX, String titleY, boolean showXAxis, String chartTitle) { DefaultCategoryDataset myData = new DefaultCategoryDataset(); JFreeChart chart1; CategoryPlot plot1; LineAndShapeRenderer lineandshaperenderer; //hide horizontal axis switch (type) { case "bar": chart1 = ChartFactory.createBarChart(chartTitle, titleY, titleX, myData, PlotOrientation.VERTICAL, false, true, false); plot1 = chart1.getCategoryPlot(); //Custom tooltips BarRenderer renderer = (BarRenderer) plot1.getRenderer(); switch (chartTitle.toLowerCase()) { case "label frequency": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "labelset frequency": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "labels histogram": renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator( "Instances with {1} labels = {2}", NumberFormat.getInstance())); break; case "ir inter class": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "ir intra class": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "ir per labelset": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("ID: {0} = {2}", NumberFormat.getInstance())); break; default: renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); break; } plot1.setBackgroundAlpha(0); plot1.setRangeGridlinePaint(Color.black); break; case "line_2_axis": chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false, true, false); plot1 = chart1.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.black); //show little rectangles lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); CategoryAxis domainAxis = plot1.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); ValueAxis axis2 = new NumberAxis("# Labels"); plot1.setRangeAxis(1, axis2); plot1.mapDatasetToRangeAxis(1, 1); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); plot1.setRenderer(1, renderer2); break; default: //type == "line") chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false, true, false); plot1 = chart1.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.black); //show little rectangles lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); break; } //Hide X axis plot1.getDomainAxis().setTickLabelsVisible(showXAxis); ChartPanel cp1 = new ChartPanel(chart1); cp1.setSize(new Dimension(450, 300)); cp1.setBounds(260, 100, 450, 300); cp1.setPreferredSize(new Dimension(450, 300)); cp1.repaint(); jpanel.setBounds(260, 100, 450, 300); jpanel.setLayout(new BorderLayout()); jpanel.add(cp1, BorderLayout.CENTER); jpanel.repaint(); jpanel.validate(); return cp1; }