List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:charts.Chart.java
public static void MultipleLineChart(XYDataset[] datasets, String title, String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue) { JFrame chartwindow = new JFrame(title); CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis(x_axis_label)); for (int i = 0; i < datasets.length; i++) { XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setBaseSeriesVisibleInLegend(showlegend); XYPlot subplot = new XYPlot(datasets[i], null, new NumberAxis(y_axis_label), renderer); NumberAxis axis = (NumberAxis) subplot.getRangeAxis(); //axis.setTickLabelFont(new Font("SansSerif", Font.BOLD,12)); //axis.setLabelFont(new Font("SansSerif", Font.PLAIN,10)); axis.setAutoRangeIncludesZero(true); axis.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); NumberAxis daxis = (NumberAxis) parent.getDomainAxis(); daxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); parent.add(subplot, 1);/*from w w w . j a v a 2s . c o m*/ } JFreeChart jfreechart = new JFreeChart(title, parent); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:mio_de_pso.MainForm.java
private void createPlots() { deMainPlot = new XYPlot(null, domainAxis, rangeAxis, Renderer); deMainPlot.setDataset(xyzSet);//w w w . java 2 s. co m deChart = new JFreeChart("Differential Evolution", null, deMainPlot, false); deChartPanel = new ChartPanel(deChart); DEPanel.removeAll(); DEPanel.add(deChartPanel, java.awt.BorderLayout.CENTER); psoMainPlot = new XYPlot(null, domainAxis, rangeAxis, Renderer); psoMainPlot.setDataset(xyzSet); psoChart = new JFreeChart("Particle Swarm optimization", null, psoMainPlot, false); psoChartPanel = new ChartPanel(psoChart); PSOPanel.removeAll(); PSOPanel.add(psoChartPanel, java.awt.BorderLayout.CENTER); this.validate(); }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChart(Set<QuantDiseaseGroupsComparison> selectedComparisonList) { if (userCustomizedComparison != null) { return updateBubbleChartChartWithCustUserData(selectedComparisonList); }/*from w ww. ja va 2 s. c o m*/ tooltipsProtNumberMap.clear(); DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2 || qp.getSignificantTrindCategory() == 5) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { double[] tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[3] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[x] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.LIGHT_GRAY }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int i = 0; @Override public RectangleInsets getTickLabelInsets() { // System.out.println("at ---- super.getTickLabelInsets() " + super.getTickLabelInsets()); // if (i == 0) { // i++; // return new RectangleInsets(-5, -5, 0, 0); // }else // return super.getTickLabelInsets(); //To change body of generated methods, choose Tools | Templates. } int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 2]; int x = 0; xAxisLabels[x] = ""; int maxLength = -1; //init labels color final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 2]; diseaseGroupslabelsColor[x] = Color.WHITE; x++; for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); String updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x].length() > maxLength) { maxLength = xAxisLabels[x].length(); } diseaseGroupslabelsColor[x] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x] = ""; diseaseGroupslabelsColor[x] = Color.WHITE; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); // legend.setMargin(20, 0, 0, 0); //// legend.setBorder(1, 1, 1, 1); // legend.setFrame(new BlockBorder(1, 0, 1, 0, Color.LIGHT_GRAY)); // generatedChart.removeLegend(); // xyplot.setForegroundAlpha(0.65F); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); // exporter.writeChartToPDFFile(generatedChart, 595, 842, "bublechart.pdf"); return generatedChart; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createMonthlyLoginChart(int width, int height) { IntervalXYDataset dataset1 = getMonthlyLoginsDataSet(); IntervalXYDataset dataset3 = getMonthlySiteUserDataSet(); if ((dataset1 == null) || (dataset3 == null)) { return generateNoDataChart(width, height); }/*from ww w. j ava2 s . c om*/ // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.RED); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("yyyy-MM"))); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setVerticalTickLabels(true); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis axis1 = new NumberAxis("Total Logins"); axis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis1.setLabelPaint(Color.RED); axis1.setTickLabelPaint(Color.RED); XYPlot plot1 = new XYPlot(dataset1, null, axis1, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // AXIS 2 /* NumberAxis axis2 = new NumberAxis("Total Unique Users"); axis2.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); axis2.setLabelPaint(Color.BLUE); axis2.setTickLabelPaint(Color.BLUE); plot1.setRangeAxis(1, axis2); plot1.setDataset(1, dataset2); plot1.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint (0, Color.BLUE); plot1.setRenderer(1, renderer2); */ // add a third dataset and renderer... XYItemRenderer renderer3 = new XYLineAndShapeRenderer(true, false); renderer3.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer3.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer3.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer3.setSeriesPaint(0, Color.GREEN); renderer3.setSeriesPaint(1, Color.BLACK); renderer3.setSeriesPaint(2, Color.CYAN); axis1 = new NumberAxis("count"); axis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot2 = new XYPlot(dataset3, null, axis1, renderer3); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample overlaid chart. * <P>//w ww .ja v a 2 s. c o m * Note: with the introduction of multiple secondary datasets in JFreeChart version 0.9.10, * the overlaid chart facility has been removed. You can achieve the same results using * a regular XYPlot with multiple datasets. * * @return an overlaid chart. */ public JFreeChart createOverlaidChart() { // create a default chart based on some sample data... final String title = this.resources.getString("combined.overlaid.title"); final String subtitleStr = this.resources.getString("combined.overlaid.subtitle"); final String domainAxisLabel = this.resources.getString("combined.overlaid.domain"); final String rangeAxisLabel = this.resources.getString("combined.overlaid.range"); // create high-low and moving average dataset final DefaultHighLowDataset highLowData = DemoDatasetFactory.createHighLowDataset(); // make an overlaid plot final ValueAxis domainAxis = new DateAxis(domainAxisLabel); final NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); rangeAxis.setAutoRangeIncludesZero(false); final XYItemRenderer renderer1 = new HighLowRenderer(); renderer1.setToolTipGenerator(new HighLowItemLabelGenerator()); final XYPlot plot = new XYPlot(highLowData, domainAxis, rangeAxis, renderer1); // overlay a moving average dataset final XYDataset maData = MovingAverage.createMovingAverage(highLowData, " (Moving Average)", 5 * 24 * 60 * 60 * 1000L, 5 * 24 * 60 * 60 * 1000L); plot.setDataset(1, maData); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0"))); plot.setRenderer(1, renderer2); // make the top level JFreeChart object final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart ChartMeds(String demographicNo, String patientName, String chartTitle, String[] drugs) { MiscUtils.getLogger().debug("In ChartMeds"); org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", "MEDS", dataset, true, true, true);/*w w w . j a va 2 s . com*/ XYPlot plot = chart.getXYPlot(); // plot.getDomainAxis().setAutoRange(true); // Range rang = plot.getDataRange(plot.getRangeAxis()); // // log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin() + " eee " + plot.getDomainAxis().getLowerMargin()); // plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin()*6); // plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin()*6); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin()*1.7); // // plot.getDomainAxis().setUpperMargin(0.9); // plot.getDomainAxis().setLowerMargin(0.9); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4); XYTaskDataset drugDataset = getDrugDataSet(demographicNo, drugs); SymbolAxis yAxis = new SymbolAxis("Meds", getDrugSymbol(demographicNo, drugs)); yAxis.setGridBandsVisible(false); XYBarRenderer xyrenderer = new XYBarRenderer(); xyrenderer.setUseYInterval(true); xyrenderer.setBarPainter(new StandardXYBarPainter()); //XYPlot xyplot = new XYPlot(drugDataset, xAxis, yAxis, xyrenderer); XYPlot xyplot = new XYPlot(drugDataset, plot.getDomainAxis(), yAxis, xyrenderer); xyplot.getDomainAxis().setUpperMargin(0.9); xyplot.getDomainAxis().setLowerMargin(0.9); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new DateAxis("Date/Time")); cplot.add(xyplot); chart = new JFreeChart(chartTitle, cplot); chart.setBackgroundPaint(Color.white); return chart; }
From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java
/** Build combined chart containing the account cash/stocks/total values chart over dates on bottom and the percentage change over dates chart on top. /*from www . jav a2s . c o m*/ @return y-axes that need to be re-ranged when data changes. **/ private NumberAxis[] plotAccountHistory(XYDataset accountData, String title, Date startDate, Date endDate) { final DateAxis dateAxis = new DateAxis(); dateAxis.setRange(startDate, endDate); final NumberAxis percentAxis = new NumberAxis("% change"); percentAxis.setAutoRangeIncludesZero(false); final NumberAxis priceAxis = new NumberAxis("US$"); priceAxis.setAutoRangeIncludesZero(true); boolean useShapes = // use shapes if 3 months or less (endDate.getTime() - startDate.getTime() < 93 * 24 * 60 * 60 * 1000L); XYLineAndShapeRenderer accountRenderer = new XYLineAndShapeRenderer(); accountRenderer.setShapesVisible(useShapes); XYPlot accountPlot = new XYPlot(accountData, dateAxis, priceAxis, accountRenderer); // compare only total percent data to zoom in on its fluctuations // for comparison with the compare index such as S&P500 index. // Stock value starts at zero, and cash value becomes close to zero, // so they fluctuation widely, so leave them out. XYDataset accountTotalPercentData = new XYDatasetPercentChangeAdapter( new SubSeriesDataset(accountData, BalanceHistoryXYDataset.TOTAL_SERIES)); XYLineAndShapeRenderer compareRenderer = new XYLineAndShapeRenderer(); compareRenderer.setShapesVisible(useShapes); XYPlot comparePlot = new XYPlot(accountTotalPercentData, dateAxis, percentAxis, compareRenderer); String compareIndexSymbol = this.compareIndexSymbolField.getText(); StockHistory compareHistory = this.histories.get(compareIndexSymbol); if (compareHistory != null) { XYDataset comparePercentData = new OHLCDatasetPercentChangeAdapter(new OHLCDatasetSubdomainAdapter( new OHLCDatasetOfStockHistory(compareHistory), startDate, endDate)); int compareIndex = 1; comparePlot.setDataset(compareIndex, comparePercentData); XYLineAndShapeRenderer percentRenderer = new XYLineAndShapeRenderer(); percentRenderer.setShapesVisible(useShapes); comparePlot.setRenderer(compareIndex, percentRenderer); } // share date axis CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(dateAxis); combinedPlot.add(comparePlot, 1); combinedPlot.add(accountPlot, 1); this.chartPanel.setChart(new JFreeChart(title, null, combinedPlot, true)); return new NumberAxis[] { priceAxis, percentAxis }; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a horizontally combined chart. * * @return a horizontally combined chart. *//*from ww w . j av a 2s . c o m*/ public JFreeChart createHorizontallyCombinedChart() { // create a default chart based on some sample data... final String title = this.resources.getString("combined.horizontal.title"); final String subtitleStr = this.resources.getString("combined.horizontal.subtitle"); final String[] domains = this.resources.getStringArray("combined.horizontal.domains"); final String rangeAxisLabel = this.resources.getString("combined.horizontal.range"); final TimeSeriesCollection dataset0 = new TimeSeriesCollection(); final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries(); dataset0.addSeries(eur); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(); final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30); dataset1.addSeries(eur); dataset1.addSeries(mav); final TimeSeriesCollection dataset2 = new TimeSeriesCollection(); dataset2.addSeries(eur); // make a combined range plot final NumberAxis valueAxis = new NumberAxis(rangeAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis); parent.setRenderer(new StandardXYItemRenderer()); // add subplots final int[] weight = { 1, 1, 1 }; // controls space assigned to each subplot // add subplot 1... final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis(domains[0]), null, new StandardXYItemRenderer()); parent.add(subplot1, weight[0]); // add subplot 2... final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis(domains[1]), null, new StandardXYItemRenderer()); parent.add(subplot2, weight[1]); // add subplot 3... final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis(domains[2]), null, new XYBarRenderer(0.20)); parent.add(subplot3, weight[2]); // now make the top level JFreeChart final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, parent, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createWeeklyLoginChart(int width, int height) { IntervalXYDataset dataset1 = getWeeklyLoginsDataSet(); IntervalXYDataset dataset2 = getWeeklySiteUserDataSet(); if ((dataset1 == null) || (dataset2 == null)) { return generateNoDataChart(width, height); }//from w w w . j a va 2 s . c om // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesPaint(0, Color.BLUE); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd"))); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setVerticalTickLabels(true); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint(0, Color.GREEN); renderer2.setSeriesPaint(1, Color.BLACK); renderer2.setSeriesPaint(2, Color.CYAN); rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample vertically combined chart. * * @return a sample vertically combined chart. *///w ww.j a va 2 s.com public JFreeChart createVerticallyCombinedChart() { // create a default chart based on some sample data... final String title = this.resources.getString("combined.vertical.title"); final String subtitleStr = this.resources.getString("combined.vertical.subtitle"); final String domain = this.resources.getString("combined.vertical.domain"); final String[] ranges = this.resources.getStringArray("combined.vertical.ranges"); final TimeSeriesCollection dataset0 = new TimeSeriesCollection(); final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries(); dataset0.addSeries(eur); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(); final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries(); final TimeSeries mav = MovingAverage.createMovingAverage(jpy, "JPY/GBP (30 Day MA)", 30, 30); dataset1.addSeries(jpy); dataset1.addSeries(mav); final XYDataset dataset2 = DemoDatasetFactory.createHighLowDataset(); final TimeSeriesCollection dataset3 = new TimeSeriesCollection(); dataset3.addSeries(eur); // make one shared horizontal axis final ValueAxis timeAxis = new DateAxis(domain); // make a vertically CombinedPlot that will contain the sub-plots final CombinedDomainXYPlot multiPlot = new CombinedDomainXYPlot(timeAxis); final int[] weight = { 1, 1, 1, 1 }; // control vertical space allocated to each sub-plot // add subplot1... final XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]), new StandardXYItemRenderer()); final NumberAxis range1 = (NumberAxis) subplot1.getRangeAxis(); range1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range1.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range1.setAutoRangeIncludesZero(false); multiPlot.add(subplot1, weight[0]); // add subplot2... final XYPlot subplot2 = new XYPlot(dataset1, null, new NumberAxis(ranges[1]), new StandardXYItemRenderer()); final NumberAxis range2 = (NumberAxis) subplot2.getRangeAxis(); range2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range2.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range2.setAutoRangeIncludesZero(false); multiPlot.add(subplot2, weight[1]); // add subplot3... final XYPlot subplot3 = new XYPlot(dataset2, null, new NumberAxis(ranges[2]), null); final XYItemRenderer renderer3 = new HighLowRenderer(); subplot3.setRenderer(renderer3); final NumberAxis range3 = (NumberAxis) subplot3.getRangeAxis(); range3.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range3.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range3.setAutoRangeIncludesZero(false); multiPlot.add(subplot3, weight[2]); // add subplot4... final XYPlot subplot4 = new XYPlot(dataset3, null, new NumberAxis(ranges[3]), null); final XYItemRenderer renderer4 = new XYBarRenderer(); subplot4.setRenderer(renderer4); final NumberAxis range4 = (NumberAxis) subplot4.getRangeAxis(); range4.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range4.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range4.setAutoRangeIncludesZero(false); multiPlot.add(subplot4, weight[3]); // now make the top level JFreeChart that contains the CombinedPlot final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, multiPlot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }