List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis
public ValueAxis getRangeAxis()
From source file:org.jgrasstools.gears.ui.OmsMatrixCharter.java
private JFreeChart doBarChart() { XYSeriesCollection collection = getSeriesCollection(); XYBarDataset xyBarDataset = new XYBarDataset(collection, minInterval); PlotOrientation orientation = PlotOrientation.VERTICAL; if (doHorizontal) { orientation = PlotOrientation.HORIZONTAL; }//w w w. j a v a 2 s. co m JFreeChart chart = ChartFactory.createHistogram(inTitle, inLabels[0], inLabels[1], xyBarDataset, orientation, doLegend, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.85f); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); double delta = (max - min) * 0.1; yAxis.setRange(min, max + delta); yAxis.setMinorTickCount(4); yAxis.setMinorTickMarksVisible(true); if (inFormats != null && inFormats.length > 0 && inFormats[1].trim().length() > 0) { yAxis.setNumberFormatOverride(new DecimalFormat(inFormats[1])); } if (inFormats != null && inFormats.length > 0 && inFormats[0].trim().length() > 0) { ValueAxis domainAxis = plot.getDomainAxis(); if (domainAxis instanceof NumberAxis) { NumberAxis xAxis = (NumberAxis) domainAxis; xAxis.setNumberFormatOverride(new DecimalFormat(inFormats[0])); } } XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setShadowVisible(false); if (inColors != null) { String[] colorSplit = inColors.split(";"); for (int i = 0; i < colorSplit.length; i++) { String[] split = colorSplit[i].split(","); int r = (int) Double.parseDouble(split[0]); int g = (int) Double.parseDouble(split[1]); int b = (int) Double.parseDouble(split[2]); renderer.setSeriesPaint(i, new Color(r, g, b)); } } return chart; }
From source file:compecon.dashboard.panel.AbstractChartsPanel.java
protected void configureChart(JFreeChart chart) { chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); DateAxis dateAxis = (DateAxis) plot.getDomainAxis(); NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM")); valueAxis.setAutoRangeIncludesZero(true); valueAxis.setUpperMargin(0.15);/*from w w w .java 2 s . c om*/ valueAxis.setLowerMargin(0.15); }
From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java
private JFreeChart createChart(String yLabel) { //Create the chart final JFreeChart chart = ChartFactory.createXYLineChart("Chart", "Time", yLabel, null); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer);//from w w w . j a v a 2 s. c om // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java
private JFreeChart getMemoryChart(int intervalSize, List<MemoryData> memory) { if (null == memory || memory.isEmpty()) { return null; }/*from w ww. ja va 2s. c om*/ JFreeChart chart; TimeSeries freeSeries = new TimeSeries("Free"); TimeSeries maxSeries = new TimeSeries("Max"); TimeSeries totalSeries = new TimeSeries("Total"); memory.remove(memory.size() - 1); for (MemoryData memoryEntry : memory) { freeSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getFreeMemory()); maxSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getMaxMemory()); totalSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getTotalMemory()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(freeSeries); dataset.addSeries(maxSeries); dataset.addSeries(totalSeries); chart = ChartFactory.createTimeSeriesChart("eID Trust Service Memory Usage History", "Time (interval size " + intervalSize + " msec)", "Memory", dataset, true, false, false); chart.addSubtitle(new TextTitle( memory.get(0).getDate().toString() + " - " + memory.get(memory.size() - 1).getDate().toString())); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); plot.setRenderer(renderer); return chart; }
From source file:physical_network.OscilloscopePanel.java
public OscilloscopePanel() { super("Oscilloscope"); // Set initial (time, voltage) datapoint of (0.0, 0.0). voltages.add(0.0, 0.0);/*www .j a v a 2s . co m*/ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(voltages); JFreeChart chart = ChartFactory.createXYLineChart("Oscilloscope", "Time (seconds)", "Voltage", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(0.0, 10.0); domain.setTickUnit(new NumberTickUnit(1.0)); domain.setVerticalTickLabels(true); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setRange(-5.0, 5.0); range.setTickUnit(new NumberTickUnit(1.0)); plot.setRenderer(renderer); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(chartPanel); }
From source file:com.kurvlrgui.gui.ChartPanel.java
/** * Creates new form ChartPanel/*from ww w. j a v a2 s . co m*/ */ public ChartPanel(String title, NumericData s1, NumericData s2) { initComponents(); calculated = new XYSeries("Calculated"); for (NumericPair np : s1.values) { calculated.add(np.x, np.y); } observed = null; if (s2 != null) { observed = new XYSeries("Observed"); for (NumericPair np : s2.values) { observed.add(np.x, np.y); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(calculated); if (s2 != null) dataset.addSeries(observed); JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); panel = new org.jfree.chart.ChartPanel(chart); panel.setHorizontalAxisTrace(true); panel.setVerticalAxisTrace(true); this.add(panel); }
From source file:de.hs.mannheim.modUro.controller.diagram.DiagramController.java
/** * Creates JFreeChart. XYLineDiagram.//from w w w. j a v a2s. co m * * @param dataset * @return */ protected JFreeChart createChart(XYDataset dataset, String metricTypeName) { String title = metricTypeName; JFreeChart xyLineChart = ChartFactory.createXYLineChart(title, // title "t", // x-axis label "f", // y-axis label dataset); String fontName = "Palatino"; xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); XYPlot plot = (XYPlot) xyLineChart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLowerMargin(0.0); plot.getRangeAxis().setRange(0.0, 1.01); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); xyLineChart.getLegend().setFrame(BlockBorder.NONE); xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, new Color(24, 123, 58)); renderer.setSeriesPaint(2, new Color(149, 201, 136)); renderer.setSeriesPaint(3, new Color(1, 62, 29)); renderer.setSeriesPaint(4, new Color(81, 176, 86)); renderer.setSeriesPaint(5, new Color(0, 55, 122)); renderer.setSeriesPaint(6, new Color(0, 92, 165)); } return xyLineChart; }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateChartByType(String title, String xLabel, String yLabel, Dataset dataset, String outputdir, String type, String filename) throws IOException { JFreeChart jChart = null;/*from w w w.java 2 s.c o m*/ if ("line".equalsIgnoreCase(type)) { jChart = ChartFactory.createLineChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } else if ("bar".equalsIgnoreCase(type)) { System.out.println("Setting up jChart"); jChart = ChartFactory.createBarChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); System.out.println("Writing image...."); } else if ("xyline".equalsIgnoreCase(type)) { jChart = ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } if ("xyline".equalsIgnoreCase(type)) { XYPlot plot = (XYPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); domain.setAutoRangeIncludesZero(false); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } else { CategoryPlot plot = (CategoryPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); CategoryAxis domain = (CategoryAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + filename + ".png"), jChart, 900, 500); }
From source file:org.owasp.benchmark.score.report.ScatterScores.java
private JFreeChart display(String title, int height, int width, List<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (int i = 0; i < toolResults.size(); i++) { Report toolReport = toolResults.get(i); OverallResults overallResults = toolReport.getOverallResults(); series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); }/*from w w w. ja va2 s.c o m*/ dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-5, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String label = ""+((String)dataset.getSeries(i).getKey()); // int idx = label.indexOf( ':'); // label = label.substring( 0, idx ); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(toolResults, xyplot); makeLegend(toolResults, 57, 48, dataset, xyplot); Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } // // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.interpss.chart.dist.LoadScheduleChart.java
public void createChart() { final JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xLabel, voltYLabel, createDataSet(voltDataAry, voltDataLabel), PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = (XYPlot) chart.getPlot(); final XYStepRenderer renderer = new XYStepRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer);// w ww .ja va 2 s.c o m //NumberAxis axis_x = (NumberAxis) plot.getDomainAxis(); //axis_x.setRangeAboutValue(12.0, 24.0); final NumberAxis axisLeft = (NumberAxis) plot.getRangeAxis(); axisLeft.setAutoRangeIncludesZero(false); axisLeft.setAutoRangeMinimumSize(1.0); final NumberAxis axisRight = new NumberAxis(pqYLabel); axisRight.setAutoRangeIncludesZero(false); axisRight.setAutoRangeMinimumSize(1.0); plot.setRangeAxis(1, axisRight); final XYItemRenderer v_renderer = plot.getRenderer(0); v_renderer.setSeriesPaint(0, vColor); plot.setDataset(1, createDataSet(pDataAry, pDataLabel)); plot.mapDatasetToRangeAxis(1, 1); final XYStepRenderer p_renderer = new XYStepRenderer(); p_renderer.setSeriesPaint(0, pColor); p_renderer.setBaseShapesVisible(false); plot.setRenderer(1, p_renderer); plot.setDataset(2, createDataSet(qDataAry, qDataLabel)); plot.mapDatasetToRangeAxis(2, 1); final XYStepRenderer q_renderer = new XYStepRenderer(); q_renderer.setSeriesPaint(0, qColor); q_renderer.setBaseShapesVisible(false); plot.setRenderer(2, q_renderer); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(Chart_Width, Chart_Height)); setContentPane(chartPanel); }