List of usage examples for org.jfree.chart JFreeChart JFreeChart
public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend)
From source file:playground.yu.utils.charts.TimeLineChart.java
private JFreeChart createChart(String title, String timeAxisLabel, String valueAxisLabel, final TimeTableXYDataset dataset) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*from ww w.jav a 2s . co m*/ NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; boolean tooltips = false; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; boolean urls = false; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true/* line */, false/* shape */); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); boolean legend = true; JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:net.sf.mzmine.modules.visualization.twod.TwoDPlot.java
TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset, Range rtRange, Range mzRange) {/*from ww w .j av a2 s . c o m*/ super(null, true); this.rawDataFile = rawDataFile; this.rtRange = rtRange; this.mzRange = mzRange; setBackground(Color.white); setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); // set the X axis (retention time) properties xAxis = new NumberAxis("Retention time"); xAxis.setAutoRangeIncludesZero(false); xAxis.setNumberFormatOverride(rtFormat); xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); // set the Y axis (intensity) properties yAxis = new NumberAxis("m/z"); yAxis.setAutoRangeIncludesZero(false); yAxis.setNumberFormatOverride(mzFormat); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); // set the plot properties plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); // chart properties chart = new JFreeChart("", titleFont, plot, false); chart.setBackgroundPaint(Color.white); setChart(chart); // title chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartSubTitle = new TextTitle(); chartSubTitle.setFont(subTitleFont); chartSubTitle.setMargin(5, 0, 0, 0); chart.addSubtitle(chartSubTitle); // disable maximum size (we don't want scaling) setMaximumDrawWidth(Integer.MAX_VALUE); setMaximumDrawHeight(Integer.MAX_VALUE); // set crosshair (selection) properties plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairPaint(crossHairColor); plot.setDomainCrosshairStroke(crossHairStroke); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); peakDataRenderer = new PeakDataRenderer(); JMenuItem plotTypeMenuItem = new JMenuItem("Toggle centroid/continuous mode"); plotTypeMenuItem.addActionListener(visualizer); plotTypeMenuItem.setActionCommand("SWITCH_PLOTMODE"); add(plotTypeMenuItem); JPopupMenu popupMenu = getPopupMenu(); popupMenu.addSeparator(); popupMenu.add(plotTypeMenuItem); }
From source file:com.bdb.weather.display.stripchart.StripChart.java
/** * Constructor.//from ww w . j a v a 2 s . com * * @param leftAxisType The type of data that is associated with the left axis * @param rightAxisType The type of data that is associated with the right axis * @param categorySpanHours How many hours that the X axis should initially display * @param maxSpanHours The maximum amount of data to keep in the plots dataset */ public StripChart(MeasurementType leftAxisType, MeasurementType rightAxisType, int categorySpanHours, int maxSpanHours) { span = categorySpanHours; this.maxSpanHours = maxSpanHours; // // Set up the Y axes // setLeftAxis(leftAxisType); setRightAxis(leftAxisType); // // Set up the X axis // dateAxis = new DateAxis("Time"); dateAxis.setAutoRange(false); dateAxis.setDateFormatOverride(new SimpleDateFormat("h:mm a")); dateAxis.setVerticalTickLabels(true); dateAxis.setUpperMargin(.10); plot.setDomainAxis(dateAxis); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(1, 1); adjustDateAxis(Calendar.getInstance()); chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartFactory.getChartTheme().apply(chart); chartViewer = new ChartViewer(chart); this.setCenter(chartViewer); chart.getLegend().setPosition(RectangleEdge.RIGHT); }
From source file:com.sixrr.metrics.ui.charts.DistributionDialog.java
private JFreeChart createChart(XYDataset dataset) { final String title = getTitle(); final NumberAxis xAxis = new NumberAxis(metricName); xAxis.setAutoRangeIncludesZero(false); if (metricType == MetricType.Ratio || metricType == MetricType.RecursiveRatio) { xAxis.setNumberFormatOverride(new PercentFormatter()); }// www. j a va 2s.c om final NumberAxis yAxis = new NumberAxis("%"); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true); }
From source file:com.liferay.server.admin.web.internal.portlet.action.ViewChartMVCResourceCommand.java
protected JFreeChart getJFreeChart(String title, MeterPlot meterPlot) { JFreeChart jFreeChart = new JFreeChart(title, new Font(null, Font.PLAIN, 13), meterPlot, true); jFreeChart.removeLegend();//from ww w . j ava 2 s. co m jFreeChart.setBackgroundPaint(Color.white); return jFreeChart; }
From source file:ch.epfl.leb.sass.ijplugin.SimulatorStatusFrame.java
/** * Creates a new status frame./*from w w w.ja v a 2 s .c o m*/ * * @param groundTruthYLabel The y-axis label for the ground truth signal. * @param analyzerYLabel The units output by the analyzer. * @param setpointYLabel The units of the controller setpoint. * @param outputYLabel The units output by the controller. */ public SimulatorStatusFrame(String groundTruthYLabel, String analyzerYLabel, String setpointYLabel, String outputYLabel) { String seriesLabel = ""; String yLabel = ""; CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new NumberAxis("Simulation Outputs")); Font yLabelFont = new Font("Dialog", Font.PLAIN, 10); datasets = new XYSeriesCollection[4]; for (int i = 0; i < SUBPLOT_COUNT; i++) { switch (i) { case 0: seriesLabel = "True density"; yLabel = groundTruthYLabel; break; case 1: seriesLabel = "Analyzer output"; yLabel = analyzerYLabel; break; case 2: seriesLabel = "Setpoint"; yLabel = setpointYLabel; break; case 3: seriesLabel = "Controller output"; yLabel = outputYLabel; break; } XYSeries timeseries = new XYSeries(seriesLabel); datasets[i] = new XYSeriesCollection(timeseries); NumberAxis numberaxis = new NumberAxis(yLabel); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setNumberFormatOverride(new DecimalFormat("###0.00")); XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer()); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.getRangeAxis().setLabelFont(yLabelFont); combineddomainxyplot.add(xyplot); } JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, true); jfreechart.setBorderPaint(Color.black); jfreechart.setBorderVisible(true); jfreechart.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); ValueAxis valueaxis = combineddomainxyplot.getDomainAxis(); valueaxis.setAutoRange(true); // Number of frames to display valueaxis.setFixedAutoRange(2000D); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(800, 500)); chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chartpanel.setVisible(true); JPanel jPanel = new JPanel(); jPanel.setLayout(new BorderLayout()); jPanel.add(chartpanel, BorderLayout.NORTH); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); add(jPanel); pack(); setVisible(true); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.shared.interfaces.PriceChart.java
public JPanel getChartPanel() { XYSeriesCollection collection = new XYSeriesCollection(); Enumeration en = lines.elements(); while (en.hasMoreElements()) { XYSeries series = (XYSeries) en.nextElement(); collection.addSeries(series);/*from w w w. j a v a 2 s . c o m*/ } NumberAxis yAxis = new NumberAxis("Price"); NumberAxis xAxis = new NumberAxis("Time"); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(collection, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart("Price Chart", new Font("Arial", 0, 12), plot, true); ChartPanel chartPanel = new ChartPanel(chart, false, false, false, false, false); return chartPanel; }
From source file:net.sf.statcvs.output.xml.chart.ModuleActivityChart.java
private JFreeChart createContourPlot() { String title = Settings.getProjectName(); String xAxisLabel = I18n.tr("Date"); String yAxisLabel = I18n.tr("Modules"); String zAxisLabel = I18n.tr("Commit Activity (%)"); xAxis = new DateAxis(xAxisLabel); //xAxis = new HorizontalNumberAxis(xAxisLabel); List dirs = content.getDirectories(); String[] ax = new String[dirs.size()]; for (int i = 0; i < dirs.size(); i++) { ax[i] = (String) ((Directory) dirs.get(i)).getPath(); }// w ww . j a v a2s .c om yAxis = new AlignedVerticalSymbolicAxis(yAxisLabel, ax); zAxis = new ColorBar(zAxisLabel); //yAxis.setAutoRangeIncludesZero(false); //zAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(true); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); //zAxis.setInverted(false); //zAxis.setTickMarksVisible(true); ContourDataset data = createDataset(); ContourPlot plot = new ContourPlot(data, xAxis, yAxis, zAxis); //plot.setRenderAsPoints(true); ratio = Math.abs(ratio); // don't use plot units for ratios when x axis is date plot.setDataAreaRatio(ratio); return new JFreeChart(title, null, plot, false); }
From source file:com.wattzap.view.graphs.MMPGraph.java
public MMPGraph(XYSeries series) { super();/*from ww w .ja v a 2 s. c om*/ NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt")); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); double maxY = series.getMaxY(); yAxis.setRange(0, maxY + 20); yAxis.setTickLabelPaint(Color.white); yAxis.setLabelPaint(Color.white); LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time")); xAxis.setTickLabelPaint(Color.white); xAxis.setBase(4); xAxis.setAutoRange(false); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setRange(1, series.getMaxX() + 500); xAxis.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { long millis = (long) number * 1000; if (millis >= 60000) { return new StringBuffer(String.format("%d m %d s", TimeUnit.MILLISECONDS.toMinutes((long) millis), TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } else { return new StringBuffer(String.format("%d s", TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return new StringBuffer(String.format("%s", number)); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis, new XYLineAndShapeRenderer(true, false)); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.gray); plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.darkGray); /*plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray);*/ ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setBackground(Color.gray); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); }
From source file:org.adempiere.webui.apps.graph.jfreegraph.PerformanceGraphBuilder.java
public JFreeChart createIndicatorChart(IndicatorModel model) { JFreeChart chart = null;/*from w w w . j a va2 s . c om*/ DefaultValueDataset data = new DefaultValueDataset((float) model.goalModel.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = model.goalModel.getColorSchema(); int rangeLo = 0; int rangeHi = 0; Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(50, 50); float[] dist = { 0.0f, 0.2f, 0.45f, 0.75f, 1.0f }; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { Color[] colors = { colorSchema.getColor(rangeHi).brighter().brighter(), colorSchema.getColor(rangeHi).brighter(), colorSchema.getColor(rangeHi), colorSchema.getColor(rangeHi).darker(), colorSchema.getColor(rangeHi).darker().darker() }; LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors); plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range p, new BasicStroke(7.0f), model.dialBackground)); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(model.dialBackground); plot.setUnits(""); plot.setDialShape(DialShape.CHORD); plot.setNeedlePaint(model.needleColor); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setValueFont(new Font("SansSerif", Font.BOLD, 8)); plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelPaint(model.tickColor); plot.setValuePaint(new Color(0.0f, 0.0f, 0.0f, 0.0f)); plot.setTickPaint(model.tickColor); // chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 9), plot, false); return chart; }