List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setLegendLine
public void setLegendLine(Shape line)
From source file:grafix.graficos.comparativo.ConstrutorGraficoComparativos.java
private static JFreeChart criarChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Comparativo da Evoluo de Papis", "Perodo", "Evoluo (%)", dataset, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); GeneralPath zigzag = new GeneralPath(); zigzag.moveTo(-6.0f, 0.0f);//from www .j a v a 2s.c o m zigzag.lineTo(-3.0f, 6.0f); zigzag.lineTo(3.0f, -6.0f); zigzag.lineTo(6.0f, 0.0f); renderer.setLegendLine(zigzag); return chart; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Set the shape for the Chart legend items. * * @param renderer/*from w w w. ja v a 2 s . c om*/ */ static void setLegendShape(final XYLineAndShapeRenderer renderer) { final GeneralPath pathBlock; pathBlock = new GeneralPath(); pathBlock.moveTo(-7.0f, -3.0f); pathBlock.lineTo(7.0f, -3.0f); pathBlock.moveTo(-7.0f, -2.0f); pathBlock.lineTo(7.0f, -2.0f); pathBlock.moveTo(-7.0f, -1.0f); pathBlock.lineTo(7.0f, -1.0f); pathBlock.moveTo(-7.0f, 0.0f); pathBlock.lineTo(7.0f, 0.0f); pathBlock.moveTo(-7.0f, 1.0f); pathBlock.lineTo(7.0f, 1.0f); pathBlock.moveTo(-7.0f, 2.0f); pathBlock.lineTo(7.0f, 2.0f); pathBlock.moveTo(-7.0f, 3.0f); pathBlock.lineTo(7.0f, 3.0f); renderer.setLegendLine(pathBlock); }
From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java
/** * Creates the chart//from ww w . jav a 2 s .c om */ private void createChart() { JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title "Period", // x axis label "Discounted Cash", // y axis label null, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); setChart(chart); setMouseZoomable(false); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0)); renderer.setUseFillPaint(true); // the x=0 line renderer.setSeriesPaint(0, Color.GRAY); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesVisibleInLegend(0, new Boolean(false)); plot.setRenderer(renderer); }
From source file:no.ntnu.mmfplanner.ui.graph.NpvChart.java
/** * Updates the chart with data from the model. *//*w w w. ja v a 2 s .com*/ private void updateModel() { modelValid = true; XYSeriesCollection dataset = new XYSeriesCollection(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0)); renderer.setUseFillPaint(true); // the x=0 line addLineX(dataset, renderer); // rolling npv line (iterative) ProjectRoi projectRoi = ProjectRoi.getRoiTable(project, project.getInterestRate(), false); addNpvLine(projectRoi, "NPV Iterative", chartColor[0], dataset, renderer); // rolling npv line (waterfall) if (waterfall) { ProjectRoi projectRoiWaterfall = ProjectRoi.getRoiTable(project, project.getInterestRate(), true); addNpvLine(projectRoiWaterfall, "NPV Waterfall", chartColor[1], dataset, renderer); } // legend (break even and self funding) addLegendElements(dataset, renderer); XYPlot plot = ((XYPlot) getChart().getPlot()); plot.setDataset(dataset); plot.setRenderer(renderer); plot.setDomainGridlinesVisible(false); }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
/** * This method should be called after a chart dataset is updated. It * will iterate over all XYDatasets and provide the line color and lineStyle. * If it is called before a chart has a dataset, it will not have an effect. * * @param plot// ww w . ja v a2 s . co m */ public void setXYPlotRenderer(XYPlot plot) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); int n = plot.getSeriesCount(); for (int i = 0; i < n; i++) { Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, getLineStyle(i), 0.0f); renderer.setSeriesStroke(i, stroke); renderer.setSeriesPaint(i, getPaintColor(i)); } renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5)); renderer.setBaseShapesFilled(false); renderer.setBaseShapesVisible(showMarkers); renderer.setDrawSeriesLineAsPath(true); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRenderer(renderer); }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
public void setXYPlotRendererWithPoints(XYPlot plot) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); int n = plot.getSeriesCount(); int half = (int) (n / 2.0); //assume first half are series for lines and second half are series for points for (int i = 0; i < n; i++) { if (i < half) { //Add lines Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, getLineStyle(i), 0.0f); renderer.setSeriesStroke(i, stroke); renderer.setSeriesPaint(i, getPaintColor(i)); renderer.setSeriesShapesFilled(i, false); renderer.setSeriesShapesVisible(i, showMarkers); renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5)); renderer.setDrawSeriesLineAsPath(true); } else {/*from w w w. j ava2 s. co m*/ //Add points renderer.setSeriesLinesVisible(i, false); renderer.setSeriesShapesFilled(i, false); renderer.setSeriesShapesVisible(i, true); renderer.setSeriesPaint(i, getPaintColor(i - half)); } } plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRenderer(renderer); }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GOESChartUIComponent.java
/*********************************************************************************************** * Customise the XYPlot of a new chart, e.g. for fixed range axes. * * @param datasettype/*from w w w. j a v a 2 s . com*/ * @param primarydataset * @param secondarydatasets * @param updatetype * @param displaylimit * @param channelselector * @param debug * * @return JFreeChart */ public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final JFreeChart jFreeChart; // A plain Chart is an XYPlot // with a DateAxis for the x-axis (index 0) and a NumberAxis for the y-axis (index 0). // The default renderer is an XYLineAndShapeRenderer jFreeChart = ChartHelper.createChart(primarydataset, ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug), getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit, channelselector, debug); // Customise the Chart for GOES data // Channels 0 & 1 are Data on a LogarithmicAxis, // Channel 2 is Ratio on a NumberAxis if (jFreeChart != null) { final String strLabelFlux; final String strLabelRatio; final XYPlot plot; final LogarithmicAxis axisFlux; final DateAxis axisDate; // The set of Metadata available should include the Instrument // and any items from the current observation strLabelFlux = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO); strLabelRatio = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ONE); plot = jFreeChart.getXYPlot(); //---------------------------------------------------------------------------------- // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis // The RangeAxis at index 0 is the LogarithmicAxis, to be used by Channels 0 & 1 (Data) axisFlux = new LogarithmicAxis(strLabelFlux); axisFlux.setRange(1.0E-09, 1.0E-02); axisFlux.setAllowNegativesFlag(false); axisFlux.setLog10TickLabelsFlag(true); plot.setRangeAxis(0, axisFlux); // Map the dataset to the axis plot.setDataset(INDEX_FLUX, primarydataset); plot.mapDatasetToRangeAxis(0, 0); plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); //---------------------------------------------------------------------------------- // Customise the DomainAxis at index 0 axisDate = (DateAxis) plot.getDomainAxis(); // Showing the YYYY-MM-DD makes a very long label... // ToDo Consider ThreadLocal axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); // Now customise the Flux renderer to improve legend visibility // Use the same colours as on http://www.swpc.noaa.gov/ // blue=0.5 - 4.0A red=1.0 - 8.0A ChartUIHelper.customisePlotRenderer(plot, INDEX_FLUX); //---------------------------------------------------------------------------------- // Set the RangeAxis at index 1 to a new NumberAxis, to be used by Channel 2 (Ratio) if ((secondarydatasets != null) && (secondarydatasets.size() == 1)) { final NumberAxis axisRatio; final XYLineAndShapeRenderer rendererRatio; axisRatio = new NumberAxis(strLabelRatio); plot.setRangeAxis(1, axisRatio); // The RangeAxis at index 1 is the NumberAxis, to be used by Channel 2 plot.setDataset(INDEX_RATIO, secondarydatasets.get(0)); plot.mapDatasetToRangeAxis(1, 1); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); rendererRatio = new XYLineAndShapeRenderer(); rendererRatio.setLinesVisible(true); rendererRatio.setShapesVisible(false); // Channel 2 is Ratio rendererRatio.setSeriesPaint(0, ChartUIHelper.getStandardColour(2).getColor()); rendererRatio.setLegendLine(SHAPE_LEGEND); plot.setRenderer(INDEX_RATIO, rendererRatio); //ChartHelper.customisePlotRenderer(plot, INDEX_RATIO); } } return (jFreeChart); }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
/** * Draw a chart in a panel. Good for precursors and daughters * @param parentPanel//from ww w. java 2s .co m * @param dataset * @param domainMin * @param domainMax * @param supplier * @param wg */ protected void createChartInPanel(JPanel parentPanel, XYSeriesCollection dataset, Double domainMin, Double domainMax, DrawingSupplier supplier, whichGraph wg) { if (precursorChromatogramEmpty(transitionOnPlot) && wg == whichGraph.Precursor) { precursorContainerContainerPanel.setVisible(false); if (this.getWidth() >= 100 && this.getHeight() >= 100) this.setPreferredSize(new Dimension(this.getWidth(), this.getHeight())); pack(); return; } switch (wg) { case Precursor: clearPreviousChartJunk(oldPrecursorChart); oldPrecursorChart = null; break; case Daughter: clearPreviousChartJunk(oldProductChart); oldProductChart = null; break; } JFreeChart chart = ChartFactory.createXYLineChart(null, "seconds", null, dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(new Color(220, 220, 220)); XYPlot xyp = (XYPlot) (chart.getPlot()); xyp.setBackgroundPaint(Color.WHITE); xyp.setDomainGridlinesVisible(true); xyp.setRangeGridlinesVisible(true); xyp.setDomainGridlinePaint(Color.LIGHT_GRAY); xyp.setRangeGridlinePaint(Color.LIGHT_GRAY); if (supplier != null) { xyp.setDrawingSupplier(supplier); } else { xyp.setDrawingSupplier(Utils.plainDrawingSupplier(Color.LIGHT_GRAY)); } xyp.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); CenterZoomNumberAxis axisDomain = new CenterZoomNumberAxis("seconds"); axisDomain.setAutoRangeIncludesZero(false); axisDomain.setRange(Math.max(0.0, domainMin), domainMax); axisDomain.addChangeListener(new domainAxisZoomCoordinator(axisDomain)); xyp.clearAnnotations(); xyp.setDomainAxis(axisDomain); xyp.getDomainAxis().setAutoRange(false); xyp.getRangeAxis().setAutoRange(false); XYLineAndShapeRenderer xylsr = (XYLineAndShapeRenderer) xyp.getRenderer(); xylsr.setLegendLine(Utils.legendThing(16, 6)); xylsr.setShapesFilled(true); xylsr.setBaseShapesFilled(true); PanelWithChart panelWithChart = new PanelWithChart(chart); ChartPanel cp = panelWithChart.getChartPanel(); cp.removeMouseListener(cp); cp.removeMouseMotionListener(cp); if (peaksTable != null) { MRMerMouseListener mml = new MRMerMouseListener(cp, (PeaksTableModel) peaksTable.getModel()); cp.addMouseListener(mml); cp.addMouseMotionListener(mml); } cp.setPreferredSize(new Dimension(parentPanel.getWidth(), parentPanel.getHeight() - 10)); cp.setDomainZoomable(true); cp.setRangeZoomable(false); cp.setPopupMenu(null); parentPanel.removeAll(); parentPanel.add(panelWithChart); switch (wg) { case Precursor: createChartInPanelPrecursorTasksOnly(xyp); oldPrecursorChart = xyp; break; case Daughter: createChartInPanelDaughterTasksOnly(xyp); oldProductChart = xyp; break; } parentPanel.updateUI(); listTransition.requestFocus(); }