List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static Point2D translateChartPoint(Point2D point, Rectangle2D imageArea, JFreeChart chart, int rangeAxisIndex) { XYPlot plot = chart.getXYPlot(); double x, y;/*from w w w . jav a 2 s . c o m*/ ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis; if (rangeAxisIndex < 0 || rangeAxisIndex >= plot.getRangeAxisCount()) { rangeAxis = plot.getRangeAxis(); } else { rangeAxis = plot.getRangeAxis(rangeAxisIndex); } x = domainAxis.valueToJava2D(point.getX(), imageArea, RectangleEdge.BOTTOM); y = rangeAxis.valueToJava2D(point.getY(), imageArea, RectangleEdge.LEFT); return new Point2D.Double(x, y); }
From source file:org.amanzi.splash.chart.Charts.java
public static void applyMainVisualSettings(Plot plot, String rangeAxisLablel, String domainAxisLabel, PlotOrientation orientation) {// w ww .ja v a 2 s . co m if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) plot; if (rangeAxisLablel != null) categoryPlot.getRangeAxis().setLabel(rangeAxisLablel); categoryPlot.getDomainAxis().setLabel(domainAxisLabel); categoryPlot.setOrientation(orientation); } else if (plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; if (rangeAxisLablel != null) xyPlot.getRangeAxis().setLabel(rangeAxisLablel); if (domainAxisLabel != null) if (domainAxisLabel != null) xyPlot.getDomainAxis().setLabel(domainAxisLabel); xyPlot.setOrientation(orientation); } }
From source file:com.orsonpdf.demo.PDFTimeSeriesChartDemo1.java
/** * Creates a chart./*from w ww.ja v a2s . c o m*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", null, "US cents/lb", dataset, true, false, false); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); 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().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setRangeGridlinePaint(Color.red); plot.setDomainGridlinePaint(Color.red); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.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.setBaseStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), 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 chart; }
From source file:org.jfree.graphics2d.demo.SVGTimeSeriesChartDemo1.java
/** * Creates a chart.//ww w . j a v a2 s . c o m * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", null, "US cents/lb", dataset); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); 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().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setRangeGridlinePaint(Color.GRAY); plot.setDomainGridlinePaint(Color.GRAY); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.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.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), 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 chart; }
From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java
/** * /*from w w w. ja v a2 s. com*/ */ public static JXPanel buildMDSViewFromDataSet(final Instances instances, final MDSResult mdsResult, final int maxInstances, final Listener<Instances> listener, final String... attrNameToUseAsPointTitle) throws Exception { final XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createScatterPlot("", // title "X", "Y", // axis labels dataset, // dataset PlotOrientation.VERTICAL, attrNameToUseAsPointTitle.length == 0, // legend? true, // tooltips? yes false // URLs? no ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setBackgroundPaint(Color.WHITE); xyPlot.getDomainAxis().setTickLabelsVisible(false); xyPlot.getRangeAxis().setTickLabelsVisible(false); //FIXME : should be different for Shih if (!mdsResult.isNormalized()) { String stress = FormatterUtil.DECIMAL_FORMAT .format(ClassicMDS.getKruskalStressFromMDSResult(mdsResult)); chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ",Stress=" + stress + ")" : "MDS(Stress=" + stress + ")"); } else { chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ")" : "MDS"); } final SimpleMatrix coordinates = mdsResult.getCoordinates(); buildFilteredSeries(mdsResult, xyPlot, attrNameToUseAsPointTitle); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("MDS Projection")); chartPanel.setBackground(Color.WHITE); final JButton selectionButton = new JButton("Select data"); selectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final org.jfree.data.Range XDomainRange = xyPlot.getDomainAxis().getRange(); final org.jfree.data.Range YDomainRange = xyPlot.getRangeAxis().getRange(); final Instances cInstances = mdsResult.getCollapsedInstances(); final Instances selectedInstances = new Instances(cInstances, 0); List<Instances> clusters = null; if (mdsResult.getCInstances().isCollapsed()) { clusters = mdsResult.getCInstances().getCentroidMap().getClusters(); } for (int i = 0; i < cInstances.numInstances(); i++) { final Instance centroid = instances.instance(i); if (XDomainRange.contains(coordinates.get(i, 0)) && YDomainRange.contains(coordinates.get(i, 1))) { if (mdsResult.getCInstances().isCollapsed()) { if (clusters != null) { final Instances elementsOfCluster = clusters.get(i); final int nbElements = elementsOfCluster.numInstances(); for (int k = 0; k < nbElements; k++) { selectedInstances.add(elementsOfCluster.get(k)); } } } else { selectedInstances.add(centroid); } } } if (listener != null) { listener.onAction(selectedInstances); } } }); final JXPanel allPanel = new JXPanel(); allPanel.setLayout(new BorderLayout()); allPanel.add(chartPanel, BorderLayout.CENTER); final JXPanel southPanel = new JXPanel(); southPanel.add(selectionButton); allPanel.add(southPanel, BorderLayout.SOUTH); return allPanel; }
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static JFreeChart createTimeSeriesChart(String title, List<TimeSeriesChartSpecification> specifications, String xLabel, String yLabel, ColorTheme theme) { TimeSeriesCollection dataCollection = new TimeSeriesCollection(); for (TimeSeriesChartSpecification specification : specifications) { TimeSeries series = new TimeSeries(specification.getLabel(), Millisecond.class); for (Map.Entry<Date, Double> point : specification.getData().entrySet()) { series.add(new Millisecond(point.getKey()), point.getValue()); }// ww w .ja va2 s . c om dataCollection.addSeries(series); } JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataCollection, true, false, false); formatColorTheme(chart, theme); XYPlot plot = chart.getXYPlot(); Color[] colors = generateJetSpectrum(specifications.size()); for (int i = 0; i < specifications.size(); i++) { plot.getRenderer().setSeriesPaint(i, colors[i]); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm:ss")); return chart; }
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 //from w w w . jav a 2 s . c o m * * @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.MovingAverageDemo1.java
public static JFreeChart createChart(XYDataset xydataset) { String s = "Legal & General Unit Trust Prices"; JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(s, "Date", "Price Per Unit", xydataset, true, true, false);/* w w w .j a v a2 s .com*/ XYPlot xyplot = (XYPlot) jfreechart.getPlot(); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(false); xylineandshaperenderer.setSeriesShapesVisible(0, true); xylineandshaperenderer.setUseFillPaint(true); xylineandshaperenderer.setBaseFillPaint(Color.white); } DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return jfreechart; }
From source file:msec.org.Tools.java
public static String generateFullDayChart(String filename, OneDayValue[] data, String title) { if (data[0].getValues().length != 1440) { return "data size invalid"; }/* w w w . j a va 2 s . c o m*/ if (data.length > 1) { if (data[1].getValues() == null || data[1].getValues().length != 1440) { return "data 1 invalid"; } } XYDataset xydataset = createDataset(data); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true); try { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); GregorianCalendar endgc = (GregorianCalendar) gc.clone(); endgc.add(GregorianCalendar.DATE, 1); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2)); dateaxis.setVerticalTickLabels(true); dateaxis.setLabel(""); // ValueAxis rangeAxis = xyplot.getRangeAxis();//? rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setLabelPaint(ChartColor.gray); rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setTickLabelPaint(ChartColor.gray); rangeAxis.setLowerBound(0); // jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12)); jfreechart.getLegend().setItemPaint(ChartColor.gray); jfreechart.getLegend().setBorder(0, 0, 0, 0);// // jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));// jfreechart.getTitle().setPaint(ChartColor.gray); //? xyplot.setRangeGridlinePaint(ChartColor.GRAY); xyplot.setBackgroundPaint(ChartColor.WHITE); xyplot.setOutlinePaint(null);// int w = 500; int h = 300; // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h); ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
From source file:msec.org.Tools.java
public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart, String title, int duration) { if (data.size() == 0) { return "data size invalid"; }//from ww w . j a v a 2s . com int date = Integer.parseInt(data.get(0).getDate()); GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100); XYDataset xydataset = createDaysDataset(data, startgc, chart); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true); try { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); dateaxis.setMinimumDate(startgc.getTime()); GregorianCalendar endgc = (GregorianCalendar) startgc.clone(); endgc.add(GregorianCalendar.DATE, duration); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1)); dateaxis.setVerticalTickLabels(true); dateaxis.setLabel(""); // ValueAxis rangeAxis = xyplot.getRangeAxis();//? rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setLabelPaint(ChartColor.gray); rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setTickLabelPaint(ChartColor.gray); rangeAxis.setLowerBound(0); // jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12)); jfreechart.getLegend().setItemPaint(ChartColor.gray); jfreechart.getLegend().setBorder(0, 0, 0, 0);// // jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));// jfreechart.getTitle().setPaint(ChartColor.gray); //? xyplot.setRangeGridlinePaint(ChartColor.GRAY); xyplot.setBackgroundPaint(ChartColor.WHITE); xyplot.setOutlinePaint(null);// int w = 500; int h = 300; // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h); ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }