List of usage examples for org.jfree.chart.plot XYPlot setDomainAxis
public void setDomainAxis(ValueAxis axis)
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * This is a helper method for creating a line chart. This should only do * the chart creation and not setting up the dataset. The calling method * should do the logic for the dataset setup. * @param c //www.j a va2 s .c om * * @param xyCollection * The dataset to display a chart for. * @param chartType * The chart type. This must be a valid chart type that can be * created from an XY dataset. At current only line and scatter * are supported * @param legendPosition * The position of the legend. * @param chartName * The name of the chart. * @param yaxisName * The name of the y axis. * @param xaxisName * The name of the x axis. * @return A chart of the specified chartType based on the given dataset. */ private static JFreeChart createChartFromXYDataset(Chart c, XYDataset xyCollection, ChartType chartType, LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) { boolean showLegend = !legendPosition.equals(LegendPosition.NONE); JFreeChart chart; if (chartType.equals(ChartType.LINE)) { chart = ChartFactory.createXYLineChart(chartName, xaxisName, yaxisName, xyCollection, PlotOrientation.VERTICAL, showLegend, true, false); } else if (chartType.equals(ChartType.SCATTER)) { chart = ChartFactory.createScatterPlot(chartName, xaxisName, yaxisName, xyCollection, PlotOrientation.VERTICAL, showLegend, true, false); } else { throw new IllegalArgumentException("Unknown chart type " + chartType + " for an XY dataset."); } if (chart == null) return null; XYPlot plot = (XYPlot) chart.getPlot(); // XXX the following instance check is brittle; there are many ways to represent a time // series in JFreeChart. This check uses knowledge of the inner workings of DatasetUtil. if (xyCollection instanceof TimePeriodValuesCollection) { logger.debug("Switching x-axis to date axis so labels render properly"); plot.setDomainAxis(new DateAxis(xaxisName)); // TODO user-settable date format // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); } if (legendPosition != LegendPosition.NONE) { chart.getLegend().setPosition(legendPosition.getRectangleEdge()); } if (!c.isAutoXAxisRange()) { XYPlot xyplot = chart.getXYPlot(); ValueAxis axis = xyplot.getDomainAxis(); axis.setAutoRange(false); axis.setRange(c.getXAxisMinRange(), c.getXAxisMaxRange()); } if (!c.isAutoYAxisRange()) { XYPlot xyplot = chart.getXYPlot(); ValueAxis axis = xyplot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange()); } return chart; }
From source file:org.jfree.chart.demo.MarkerDemo2.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("Marker Demo 2", "X", "Temperature", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainGridlineStroke(new BasicStroke(1.0F)); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeGridlineStroke(new BasicStroke(1.0F)); xyplot.setRangeTickBandPaint(new Color(240, 240, 240)); PeriodAxis periodaxis = new PeriodAxis(null, new Hour(0, 30, 6, 2005), new Hour(23, 30, 6, 2005)); PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Hour.class, new SimpleDateFormat("HH")); aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("dd-MMM")); periodaxis.setLabelInfo(aperiodaxislabelinfo); xyplot.setDomainAxis(periodaxis); ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 100D);//from w w w. j a va 2s . c o m XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setSeriesPaint(0, Color.green); xyitemrenderer.setSeriesStroke(0, new BasicStroke(2.0F)); ValueMarker valuemarker = new ValueMarker(80D); valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); valuemarker.setPaint(Color.red); valuemarker.setStroke(new BasicStroke(2.0F)); valuemarker.setLabel("Temperature Threshold"); valuemarker.setLabelFont(new Font("SansSerif", 0, 11)); valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addRangeMarker(valuemarker); Hour hour = new Hour(18, 30, 6, 2005); Hour hour1 = new Hour(20, 30, 6, 2005); double d = hour.getFirstMillisecond(); double d1 = hour1.getFirstMillisecond(); IntervalMarker intervalmarker = new IntervalMarker(d, d1); intervalmarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); intervalmarker.setPaint(new Color(150, 150, 255)); intervalmarker.setLabel("Automatic Cooling"); intervalmarker.setLabelFont(new Font("SansSerif", 0, 11)); intervalmarker.setLabelPaint(Color.blue); intervalmarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); intervalmarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); xyplot.addDomainMarker(intervalmarker, Layer.BACKGROUND); ValueMarker valuemarker1 = new ValueMarker(d, Color.blue, new BasicStroke(2.0F)); ValueMarker valuemarker2 = new ValueMarker(d1, Color.blue, new BasicStroke(2.0F)); xyplot.addDomainMarker(valuemarker1, Layer.BACKGROUND); xyplot.addDomainMarker(valuemarker2, Layer.BACKGROUND); return jfreechart; }
From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerAndPredictionDifference.java
private static JFreeChart createChart() { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(NAME, "Power (Watts)", "Power (Watts)", data, true, true, false);/*from ww w. j a va2 s . co m*/ jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYDifferenceRenderer xydifferencerenderer = new XYDifferenceRenderer(Color.green, Color.yellow, false); xydifferencerenderer.setRoundXCoordinates(true); xyplot.setDomainCrosshairLockedOnData(true); xyplot.setRangeCrosshairLockedOnData(true); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); xyplot.setRenderer(xydifferencerenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); DateAxis dateaxis = new DateAxis("Samples"); dateaxis.setTickLabelsVisible(false); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); xyplot.setDomainAxis(dateaxis); xyplot.setForegroundAlpha(0.5F); return jfreechart; }
From source file:umberto.WeightedClusterCoefficient.ChartUtils.java
public static void scaleLogChart(JFreeChart chart, XYSeries dSeries, boolean normalized) { XYPlot plot = (XYPlot) chart.getPlot(); final LogAxis logyAxis = new LogAxis(plot.getRangeAxis().getLabel()); final LogAxis logxAxis = new LogAxis(plot.getDomainAxis().getLabel()); //Set y axis format. // DecimalFormat formaty = (DecimalFormat) DecimalFormat.getNumberInstance(Locale.ENGLISH); // formaty.applyPattern("#0.0000"); //set y axis// w w w . j a va 2 s. co m logyAxis.setBase(10); // logyAxis.setNumberFormatOverride(formaty); logyAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH)); // logyAxis.setRange(0.01, 1.0); logyAxis.setAutoRange(true); plot.setRangeAxis(logyAxis); //set x axis logxAxis.setBase(10); logxAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH)); logxAxis.setAutoRange(true); //logxAxis.setRange(0.00001, 1.0);//Se la voglio zoommare plot.setDomainAxis(logxAxis); }
From source file:de.laures.cewolf.taglib.CewolfChartFactory.java
public static JFreeChart getCombinedChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, List plotDefinitions, String layout) throws ChartValidationException, DatasetProduceException { final int chartTypeConst = getChartTypeConstant(chartType); switch (chartTypeConst) { case COMBINED_XY: final int layoutConst = getLayoutConstant(layout); Plot plot = null;// w ww . jav a2 s. c om switch (layoutConst) { case DOMAIN: ValueAxis domainAxis = new DateAxis(xAxisLabel); plot = new CombinedDomainXYPlot(domainAxis); for (int i = 0; i < plotDefinitions.size(); i++) { PlotDefinition pd = (PlotDefinition) plotDefinitions.get(i); check((Dataset) pd.getDataset(), XYDataset.class, chartType); XYPlot temp = (XYPlot) pd.getPlot(chartTypeConst); temp.setRangeAxis(new NumberAxis(pd.getYaxislabel())); ((CombinedDomainXYPlot) plot).add(temp); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); case RANGE: ValueAxis rangeAxis = new NumberAxis(yAxisLabel); plot = new CombinedRangeXYPlot(rangeAxis); for (int i = 0; i < plotDefinitions.size(); i++) { PlotDefinition pd = (PlotDefinition) plotDefinitions.get(i); check((Dataset) pd.getDataset(), XYDataset.class, chartType); XYPlot temp = (XYPlot) pd.getPlot(chartTypeConst); temp.setDomainAxis(new DateAxis(pd.getXaxislabel())); ((CombinedRangeXYPlot) plot).add(temp); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); default: throw new AttributeValidationException(layout, " any value"); } default: throw new UnsupportedChartTypeException(chartType); } }
From source file:org.openmrs.module.usagestatistics.web.view.chart.DateRangeChartView.java
@Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { UsageStatisticsService svc = Context.getService(UsageStatisticsService.class); List<Object[]> stats = svc.getDateRangeStats(null, null, null); String xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.date"); String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records"); String seriesUsages = ContextProvider.getMessage("usagestatistics.results.views"); String seriesEncounters = ContextProvider.getMessage("usagestatistics.results.encounters"); String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates"); // Get minimum date value in returned statistics Date minDate = (stats.size() > 0) ? (Date) (stats.get(0)[0]) : getFromDate(); if (minDate.getTime() > getFromDate().getTime()) // Min date must be at least a week ago minDate = getFromDate();//from ww w . j a va 2s . c om // Maximum date defaults to today Date maxDate = (getUntilDate() != null) ? getUntilDate() : new Date(); // Build a zeroized dataset of all dates in range TimeTableXYDataset dataset = new TimeTableXYDataset(); Calendar cal = new GregorianCalendar(); cal.setTime(minDate); while (cal.getTime().getTime() <= maxDate.getTime()) { Date day = cal.getTime(); dataset.add(new Day(day), 0, seriesUsages, false); dataset.add(new Day(day), 0, seriesEncounters, false); dataset.add(new Day(day), 0, seriesUpdates, false); cal.add(Calendar.DATE, 1); } // Update the dates for which we have statistics for (Object[] row : stats) { Date date = (Date) row[0]; int usages = ((Number) row[1]).intValue(); int encounters = ((Number) row[2]).intValue(); int updates = ((Number) row[3]).intValue(); dataset.add(new Day(date), usages, seriesUsages, false); dataset.add(new Day(date), encounters, seriesEncounters, false); dataset.add(new Day(date), updates, seriesUpdates, false); } dataset.setDomainIsPointsInTime(true); JFreeChart chart = ChartFactory.createXYLineChart(null, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, false, false); DateAxis xAxis = new DateAxis(xAxisLabel); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(xAxis); return chart; }
From source file:org.jfree.chart.demo.CyclicXYPlotDemo.java
/** * A demonstration application showing an XY plot, with a cyclic axis and renderer * * @param title the frame title./* www . ja v a 2s.c o m*/ */ public CyclicXYPlotDemo(final String title) { super(title); this.series = new XYSeries("Random Data"); this.series.setMaximumItemCount(50); // Only 50 items are visible at the same time. // Keep more as a mean to test this. final XYSeriesCollection data = new XYSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createXYLineChart("Cyclic XY Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setDomainAxis(new CyclicNumberAxis(10, 0)); plot.setRenderer(new CyclicXYItemRenderer()); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeMinimumSize(1.0); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(400, 300)); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel, BorderLayout.CENTER); final JButton button1 = new JButton("Start"); button1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { timer.start(); } }); final JButton button2 = new JButton("Stop"); button2.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { timer.stop(); } }); final JButton button3 = new JButton("Step by step"); button3.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CyclicXYPlotDemo.this.actionPerformed(null); } }); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); content.add(buttonPanel, BorderLayout.SOUTH); setContentPane(content); this.timer = new Timer(200, this); }
From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java
private void configureAxis(XYPlot plot) { NumberAxis xAxis = new NumberAxis(); plot.setDomainAxis(xAxis); NumberAxis yaxis = new NumberAxis(); yaxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(yaxis);//from w ww . j av a2 s . co m }
From source file:net.relet.freimap.NodeInfo.java
private void sexupLayout(JFreeChart chart) { chart.setAntiAlias(true);//from w ww . ja va 2 s. c o m chart.setBackgroundPaint(VisorFrame.bgcolor); chart.setBorderVisible(false); TextTitle title = chart.getTitle(); title.setFont(VisorFrame.smallerfont); title.setPaint(VisorFrame.fgcolor); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(VisorFrame.bgcolor); plot.setDomainAxis(new DateAxis()); sexupAxis(plot.getDomainAxis()); sexupAxis(plot.getRangeAxis()); }
From source file:org.jfree.chart.demo.PeriodAxisDemo3.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { JFreeChart jfreechart = ChartFactory.createXYBarChart("Maximum Temperature", "Day", true, "Temperature", intervalxydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); PeriodAxis periodaxis = new PeriodAxis("Day"); periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class); PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[3]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d")); aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("E"), new RectangleInsets(2D, 2D, 2D, 2D), new Font("SansSerif", 1, 10), Color.blue, false, new BasicStroke(0.0F), Color.lightGray); aperiodaxislabelinfo[2] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM")); periodaxis.setLabelInfo(aperiodaxislabelinfo); xyplot.setDomainAxis(periodaxis); return jfreechart; }