public MultiLineChart(final String title, List<Users> tpaverficationUserList) { super(title); this.tpaverficationUserList = tpaverficationUserList; XYDataset dataset = null; try { dataset = createDataset(); } catch (Exception e) { System.out.println("MultiLineChart -- Constructor" + e); } final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(700, 470)); setContentPane(chartPanel); this.pack(); RefineryUtilities.centerFrameOnScreen(this); this.setVisible(true); }
/** * Checks that the auto-range for the domain axis on an XYPlot is * working as expected. */ public void testXYAutoRange1() { XYSeries series = new XYSeries("Series 1"); series.add(1.0, 1.0); series.add(2.0, 2.0); series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot( "Test", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false ); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getDomainAxis(); axis.setAutoRangeIncludesZero(false); assertEquals(0.9, axis.getLowerBound(), EPSILON); assertEquals(3.1, axis.getUpperBound(), EPSILON); }
@Override public JFreeChart createChart(Element element, ChartSource source) { Attribute key = source.getAttributeProperty(PIE_ATTRIBUTE_KEY); Attribute value = source.getAttributeProperty(PIE_ATTRIBUTE_VALUE); if ((key == null) || (value == null)) throw new ChartNotSetupedException(); DefaultPieDataset dataset = new DefaultPieDataset(); for (Element element2 : source.getElements()) { Object v1 = engine.getAttribute(element2, key); Object v2 = engine.getAttribute(element2, value); if ((v1 != null) && (v2 != null)) dataset.setValue(toString(v1), toDouble(v2)); } return ChartFactory.createPieChart(element.getName(), dataset, true, true, false); }
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ public void testDrawWithNullInfo() { boolean success = false; try { DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); dataset.add(1.0, 2.0, "S1", "C1"); dataset.add(3.0, 4.0, "S1", "C2"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new StatisticalLineAndShapeRenderer()); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { e.printStackTrace(); success = false; } assertTrue(success); }
public JFreeChart linePlot(String xLabel, String yLabel){ int numDatasets = dataset.size(); JFreeChart result = ChartFactory.createXYLineChart( chartTitle, // chart title xLabel, // x axis label yLabel, // y axis label dataset.get(0), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = result.getXYPlot(); plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f)); plot.getRenderer().setSeriesPaint(0, seriesColor.get(0)); for(int i=1;i<numDatasets;i++){ plot.setDataset(i,dataset.get(i)); //XYItemRenderer renderer = plot.getRenderer(i-0); //plot.setRenderer(i, new XYLineAndShapeRenderer(false, true)); plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f)); plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i)); } return result; }
/** * Creates a sample chart. * * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(IntervalXYDataset dataset,String s) { final JFreeChart chart = ChartFactory.createXYBarChart( "Histogram Plot: "+s, "Keyword index", false, "frequency", dataset, PlotOrientation.VERTICAL, true, true, false ); XYPlot plot = (XYPlot) chart.getPlot(); final IntervalMarker target = new IntervalMarker(400.0, 700.0); //target.setLabel("Target Range"); target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); target.setLabelAnchor(RectangleAnchor.LEFT); target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); target.setPaint(new Color(222, 222, 255, 128)); plot.addRangeMarker(target, Layer.BACKGROUND); return chart; }
/** * Starting point for the demonstration application. * * @param args ignored. */ public static void main(String[] args) { final JFreeChart chart = createChart(createDataset()); final Display display = new Display(); Shell shell = new Shell(display); shell.setSize(600, 300); shell.setLayout(new FillLayout()); shell.setText("Time series demo for jfreechart running with SWT"); ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true); frame.setDisplayToolTips(true); frame.setHorizontalAxisTrace(false); frame.setVerticalAxisTrace(false); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
/** * Draws the chart with a single range. At one point, this caused a null * pointer exception (fixed now). */ public void testDrawWithNullInfo() { boolean success = false; MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0)); plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0))); JFreeChart chart = new JFreeChart(plot); try { BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
public static void main(String arg[]){ XYSeries series = new XYSeries("Average Weight"); series.add(20, 20); series.add(40, 25); series.add(55, 50); series.add(70, 65); // series.add(20.0, 20.0); // series.add(40.0, 25.0); // series.add(55.0, 50.0); // series.add(70.0, 65.0); XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart", "Age", "Weight", xyDataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame1=new ChartFrame("XYLine Chart",chart); frame1.setVisible(true); frame1.setSize(300,300); }
/** * Constructor * @param chart The chart to be displayed */ public ChartTab(JFreeChart chart, ChartEditorJPanel parent) { this.parent = parent; // --- Create and configure the chart panel --- this.chartPanel = new ChartPanel(chart); this.chartPanel.setBackground(Color.WHITE); // Component background this.chartPanel.getChart().getPlot().setBackgroundPaint(Color.WHITE); // Chart background this.chartPanel.getChart().getXYPlot().setDomainGridlinePaint(Color.BLACK); this.chartPanel.getChart().getXYPlot().setRangeGridlinePaint(Color.BLACK); // --- Create the tool bar -------------------- this.rebuildVisibilityToolBar(); // --- Add components to the panel ------------ this.setLayout(new BorderLayout()); this.add(this.chartPanel, BorderLayout.CENTER); this.add(this.getJToolBarSeriesVisibility(), BorderLayout.SOUTH); // parent.getDataModel().getChartSettingModel().addObserver(this); }
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ public void testDrawWithNullInfo() { boolean success = false; try { double[][] starts = new double[][] {{0.1, 0.2, 0.3}, {0.3, 0.4, 0.5}}; double[][] ends = new double[][] {{0.5, 0.6, 0.7}, {0.7, 0.8, 0.9}}; DefaultIntervalCategoryDataset dataset = new DefaultIntervalCategoryDataset(starts, ends); IntervalBarRenderer renderer = new IntervalBarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), renderer); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { e.printStackTrace(); success = false; } assertTrue(success); }
/** * Test chart drawing with an empty dataset to ensure that this special * case doesn't cause any exceptions. */ public void testDrawWithEmptyDataset() { boolean success = false; JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x", "y", new DefaultTableXYDataset(), PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYAreaRenderer2()); try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Create a line chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createLineChart() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createLineChart( "Line Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, true ); }
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ public void testDrawWithNullInfo() { boolean success = false; try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "S1", "C1"); dataset.addValue(2.0, "S1", "C2"); dataset.addValue(3.0, "S2", "C1"); dataset.addValue(4.0, "S2", "C2"); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), renderer); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { e.printStackTrace(); success = false; } assertTrue(success); }
/** * A test for bug 1654215 (where a renderer is added to the plot without * a corresponding dataset and it throws an exception at drawing time). */ public void test1654215() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(1, new LineAndShapeRenderer()); boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { e.printStackTrace(); success = false; } assertTrue(success); }
/** * Create a stacked bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createStackedAreaChart( "Stacked Area Chart", // chart title "Domain", "Range", dataset, // data PlotOrientation.HORIZONTAL, true, // include legend true, true ); }
/** * Draws the chart with a null info object to make sure that no exceptions * are thrown. */ public void testDrawWithNullInfo() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(35.0, "S1", "C1"); dataset.addValue(45.0, "S1", "C2"); dataset.addValue(55.0, "S1", "C3"); dataset.addValue(15.0, "S1", "C4"); dataset.addValue(25.0, "S1", "C5"); SpiderWebPlot plot = new SpiderWebPlot(dataset); JFreeChart chart = new JFreeChart(plot); boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Creates a panel for the demo (used by SuperDemo.java). * * @return A panel. */ public static JPanel createDemoPanel() { JFreeChart chart = createChart(createDataset()); chart.setPadding(new RectangleInsets(4, 8, 2, 2)); ChartPanel panel = new ChartPanel(chart); // panel.setMouseWheelEnabled(true); panel.setPreferredSize(new Dimension(600, 300)); return panel; }
@Override public void start(Stage stage) throws Exception { PieDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartViewer viewer = new ChartViewer(chart); stage.setScene(new Scene(viewer)); stage.setTitle("JFreeChart: PieChartFXDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
public void paintDeviationChart(Graphics graphics, int width, int height) { prepareData(); JFreeChart chart = createChart(this.dataset); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); } Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height); chart.draw((Graphics2D) graphics, drawRect); }
/** * Creates a chart. * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart( "Pie Chart Demo 1", // chart title dataset, // data true, // include legend true, false ); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return the chart. */ private static JFreeChart createBarChart3D() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createBarChart3D( "Bar Chart 3D", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, false ); }
/** * Changes the font of {@link JFreeChart}s to Sans Serif. This method uses a * {@link StandardChartTheme} to do so, so any changes to the look of the chart must be done * after calling this method. * * @param chart * the chart to change fonts for */ protected static void setDefaultChartFonts(JFreeChart chart) { final ChartTheme chartTheme = StandardChartTheme.createJFreeTheme(); if (StandardChartTheme.class.isAssignableFrom(chartTheme.getClass())) { StandardChartTheme standardTheme = (StandardChartTheme) chartTheme; // The default font used by JFreeChart cannot render japanese etc symbols final Font oldExtraLargeFont = standardTheme.getExtraLargeFont(); final Font oldLargeFont = standardTheme.getLargeFont(); final Font oldRegularFont = standardTheme.getRegularFont(); final Font oldSmallFont = standardTheme.getSmallFont(); final Font extraLargeFont = new Font(Font.SANS_SERIF, oldExtraLargeFont.getStyle(), oldExtraLargeFont.getSize()); final Font largeFont = new Font(Font.SANS_SERIF, oldLargeFont.getStyle(), oldLargeFont.getSize()); final Font regularFont = new Font(Font.SANS_SERIF, oldRegularFont.getStyle(), oldRegularFont.getSize()); final Font smallFont = new Font(Font.SANS_SERIF, oldSmallFont.getStyle(), oldSmallFont.getSize()); standardTheme.setExtraLargeFont(extraLargeFont); standardTheme.setLargeFont(largeFont); standardTheme.setRegularFont(regularFont); standardTheme.setSmallFont(smallFont); standardTheme.apply(chart); } }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return the chart. */ private static JFreeChart createBarChart() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createBarChart( "Horizontal Bar Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, false ); }
/** * Creates the histogram chart. * * @param exampleSet * @return */ private JFreeChart createHistogramChart(final ExampleSet exampleSet) { JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainZeroBaselineVisible(false); plot.getDomainAxis().setTickLabelsVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME)); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart3D() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createBarChart3D("Bar Chart 3D", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, true, true); }
@Override public void start(Stage stage) throws Exception { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartCanvas canvas = new ChartCanvas(chart); StackPane stackPane = new StackPane(); stackPane.getChildren().add(canvas); // Bind canvas size to stack pane size. canvas.widthProperty().bind( stackPane.widthProperty()); canvas.heightProperty().bind( stackPane.heightProperty()); stage.setScene(new Scene(stackPane)); stage.setTitle("FXGraphics2DDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
/** * Starting point for the demonstration application. * * @param args ignored. */ public static void main( String[] args ) { final JFreeChart chart = createChart(); final Display display = new Display(); Shell shell = new Shell(display); shell.setSize(600, 300); shell.setLayout(new FillLayout()); shell.setText("Test for jfreechart running with SWT"); ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true); frame.setDisplayToolTips(false); frame.setHorizontalAxisTrace(true); frame.setVerticalAxisTrace(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
/** * Create a line chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createLineChart3D() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createLineChart3D( "Line Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, true ); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return the chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createScatterPlot( "Scatter Plot", // chart title "Domain", "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); }
/** * Tests the the lower and upper margin settings produce the expected * results. */ public void testAxisMargins() { XYSeries series = new XYSeries("S1"); series.add(100.0, 1.1); series.add(200.0, 2.2); XYSeriesCollection dataset = new XYSeriesCollection(series); dataset.setIntervalWidth(0.0); JFreeChart chart = ChartFactory.createScatterPlot( "Title", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false ); ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis(); Range r = domainAxis.getRange(); assertEquals(110.0, r.getLength(), EPSILON); domainAxis.setLowerMargin(0.10); domainAxis.setUpperMargin(0.10); r = domainAxis.getRange(); assertEquals(120.0, r.getLength(), EPSILON); }
public static void generateThroughputPerformChart(String dbName,long performBatchId){ String path=getChartRootPath(dbName+"_ThroughputPerform"); System.out.println(path); XYSeries values = new XYSeries(dbName); List<Map<String, Object>> list = BizDBUtils.selectListBySqlAndParam("select success_times,timeout_avg from ts_timeout_perform where perform_batch_id=? and load_type=99",performBatchId); if(list!=null&&list.size()>0){ for(int i=0;i<list.size();i++){ Map<String, Object> map = list.get(i); double timeout=((Number)map.get("timeout_avg")).doubleValue(); double successTimes=((Number)map.get("success_times")).doubleValue(); if(successTimes==0){ values.add(i+1,0); }else{ values.add(i+1,successTimes*(TimeUnit.SECONDS.toMicros(1)/timeout)); } } } XYSeriesCollection mCollection = new XYSeriesCollection(); mCollection.addSeries(values); JFreeChart mChart= createXYLineChart("数据吞吐量折线图", "请求次数","吞吐量(requests/sec)",mCollection); //saveAsFile(mChart,path, 1200, 800); saveAsFile(mChart,path, 2400, 800); }
/** * 请求吞吐量 直方图 * @param dbs */ private static void generateThroughRequestsBar(List<String> dbs) { DefaultCategoryDataset values = new DefaultCategoryDataset(); String sql="SELECT perform_batch.id, perform_batch.db db, sum(ttp.success_times) / ( sum(ttp.timeout_avg) / 1000000.0 ) AS avg, sum(ttp.success_times) / ( sum(ttp.timeout_min) / 1000000.0 ) AS max, sum(ttp.success_times) / ( sum(ttp.timeout_max) / 1000000.0 ) AS min FROM ts_timeout_perform ttp, ( SELECT batch.db db, max(tpb.id) id FROM ts_perform_batch tpb, ( SELECT max(id) id, target_db db FROM ts_load_batch tlb WHERE data_status = 1 GROUP BY target_db ) batch WHERE batch.id = tpb.load_batch_id GROUP BY tpb.load_batch_id ) perform_batch WHERE ttp.perform_batch_id = perform_batch.id AND ttp.load_type = 99 GROUP BY perform_batch.db"; List<Map<String, Object>> list = BizDBUtils.selectListBySqlAndParam(sql); if(list!=null&&list.size()>0){ for(int i=0;i<list.size();i++){ Map<String, Object> map = list.get(i); values.addValue(((Number)map.get("max")).doubleValue(),getDBName(map.get("db").toString()),"max"); values.addValue(((Number)map.get("min")).doubleValue(),getDBName(map.get("db").toString()),"min"); values.addValue(((Number)map.get("avg")).doubleValue(),getDBName(map.get("db").toString()),"avg"); } } JFreeChart mChart = createBarChart("数据库吞吐量对比图", "性能指标","speed(requests/sec)", values); String path=getChartRootPath("throughput_perform_requests_bar"); saveAsFile(mChart,path, 1200, 800); }
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ public void testDrawWithNullInfo() { boolean success = false; try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new MinMaxCategoryRenderer()); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { e.printStackTrace(); success = false; } assertTrue(success); }
private static void generateThroughPointsBar(List<String> dbs) { DefaultCategoryDataset values = new DefaultCategoryDataset(); String sql="SELECT batch.db db, sum(load_points)/(sum(load_cost_time)/1000.0) avg, max(pps) max, min(pps) min FROM ts_load_record tlr, ( SELECT max(id) id, target_db db FROM ts_load_batch tlb WHERE data_status = 1 GROUP BY target_db ) batch WHERE batch.id = tlr.load_batch_id GROUP BY load_batch_id"; List<Map<String, Object>> list = BizDBUtils.selectListBySqlAndParam(sql); if(list!=null&&list.size()>0){ for(int i=0;i<list.size();i++){ Map<String, Object> map = list.get(i); values.addValue(Double.parseDouble(df.format(((Number)map.get("max")).doubleValue())),getDBName(map.get("db").toString()),"max"); values.addValue(Double.parseDouble(df.format(((Number)map.get("min")).doubleValue())),getDBName(map.get("db").toString()),"min"); values.addValue(Double.parseDouble(df.format(((Number)map.get("avg")).doubleValue())),getDBName(map.get("db").toString()),"avg"); } } JFreeChart mChart = createBarChart("import_speed_comparison", "性能指标","speed(points/s)", values); String path=getChartRootPath("import_points_speed_comparison_line"); saveAsFile(mChart,path, 1200, 800); }
private static void generateThroughSizeBar(List<String> dbs) { DefaultCategoryDataset values = new DefaultCategoryDataset(); String sql="SELECT batch.db db, sum(load_size/1024.0/1024)/(sum(load_cost_time)/1000.0) avg, max(sps) max, min(sps) min FROM ts_load_record tlr, ( SELECT max(id) id, target_db db FROM ts_load_batch tlb WHERE data_status = 1 GROUP BY target_db ) batch WHERE batch.id = tlr.load_batch_id GROUP BY load_batch_id"; List<Map<String, Object>> list = BizDBUtils.selectListBySqlAndParam(sql); if(list!=null&&list.size()>0){ for(int i=0;i<list.size();i++){ Map<String, Object> map = list.get(i); values.addValue(Double.parseDouble(df.format(((Number)map.get("max")).doubleValue())),getDBName(map.get("db").toString()),"max"); values.addValue(Double.parseDouble(df.format(((Number)map.get("min")).doubleValue())),getDBName(map.get("db").toString()),"min"); values.addValue(Double.parseDouble(df.format(((Number)map.get("avg")).doubleValue())),getDBName(map.get("db").toString()),"avg"); } } JFreeChart mChart = createBarChart("import_speed_comparison", "性能指标","speed(MB/s)", values); String path=getChartRootPath("import_size_speed_comparison_line"); saveAsFile(mChart,path, 1200, 800); }
/** * Creates a new viewer instance. * * @param chart the chart ({@code null} permitted). * @param contextMenuEnabled enable the context menu? */ public ChartViewer(JFreeChart chart, boolean contextMenuEnabled) { this.canvas = new ChartCanvas(chart); this.canvas.setTooltipEnabled(true); this.canvas.addMouseHandler(new ZoomHandlerFX("zoom", this)); setFocusTraversable(true); getChildren().add(this.canvas); this.zoomRectangle = new Rectangle(0, 0, new Color(0, 0, 1, 0.25)); this.zoomRectangle.setManaged(false); this.zoomRectangle.setVisible(false); getChildren().add(this.zoomRectangle); this.contextMenu = createContextMenu(); setOnContextMenuRequested((ContextMenuEvent event) -> { contextMenu.show(ChartViewer.this.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); this.contextMenu.setOnShowing( e -> ChartViewer.this.getCanvas().setTooltipEnabled(false)); this.contextMenu.setOnHiding( e -> ChartViewer.this.getCanvas().setTooltipEnabled(true)); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createTimeSeriesChart( "XY Line Chart", // chart title "Domain", "Range", dataset, // data true, // include legend true, // tooltips true // urls ); }
/** * Check that the renderer is calculating the domain bounds correctly. */ public void testFindDomainBounds() { XYSeriesCollection dataset = RendererXYPackageTests.createTestXYSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart( "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); Range bounds = domainAxis.getRange(); assertFalse(bounds.contains(0.9)); assertTrue(bounds.contains(1.0)); assertTrue(bounds.contains(2.0)); assertFalse(bounds.contains(2.10)); }
public static void writeEstimatedQValueVSCalculatedQValue(File outputFile, List<SimilarityMatrix> matrices, String add, boolean FDR) throws IOException{ XYSeriesCollection dataset = new XYSeriesCollection(); for(SimilarityMatrix m:matrices){ dataset.addSeries(m.getEstimatedQValueVSCalculatedQValue(FDR, m.massbankQuery,"",Double.NEGATIVE_INFINITY,Double.POSITIVE_INFINITY)); } XYSeries seriesWH=getBisectingLine(0, 1); dataset.addSeries(seriesWH); String desc=FDR?"FDRsComparison_":"qValuesComparison_"; String desc2=FDR?"FDRs":"qValues"; final JFreeChart chart = ChartFactory.createScatterPlot(desc2, desc2+" calculated", desc2+" by decoy database", dataset); ChartUtilities.saveChartAsJPEG(new File(outputFile.getAbsolutePath()+sep+add+desc+getMethodsQueryStringFromList(matrices)+".jpg"), chart, 1000, 1000); }