List of usage examples for org.jfree.chart.plot XYPlot mapDatasetToRangeAxis
public void mapDatasetToRangeAxis(int index, int axisIndex)
From source file:netplot.GenericPlotPanel.java
void genericConfig(JFreeChart chart, XYPlot plot, int plotIndex) { if (!enableLegend) { chart.removeLegend();//from w w w .j a v a2 s. c o m } XYItemRenderer xyItemRenderer = plot.getRenderer(); //May also be XYBarRenderer if (xyItemRenderer instanceof XYLineAndShapeRenderer) { XYToolTipGenerator xyToolTipGenerator = xyItemRenderer.getBaseToolTipGenerator(); //If currently an XYLineAndShapeRenderer replace it so that we inc the colour for every plotIndex XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(linesEnabled, shapesEnabled); //Ensure we don't loose the tool tips on the new renderer renderer.setBaseToolTipGenerator(xyToolTipGenerator); renderer.setBasePaint(getPlotColour(plotIndex)); renderer.setSeriesStroke(0, new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL), true); plot.setRenderer(plotIndex, renderer); } //If we have a new y axis then we need a new data set if (yAxisName != null && yAxisName.length() > 0) { if (logYAxis) { LogAxis yAxis = new LogAxis(yAxisName); yAxis.setAutoRange(false); yAxis.setNumberFormatOverride(new LogFormat(10, "10", true)); yAxis.setRange(minScaleValue, maxScaleValue); yAxis.setLowerBound(minScaleValue); yAxis.setUpperBound(maxScaleValue); plot.setRangeAxis(yAxisIndex, yAxis); plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT); } else { NumberAxis axis = new NumberAxis(yAxisName); axis.setAutoRangeIncludesZero(zeroOnYScale); if (autoScaleEnabled) { axis.setAutoRange(true); } else { Range range = new Range(minScaleValue, maxScaleValue); axis.setRangeWithMargins(range, true, true); } if (yAxisTickCount > 0) { NumberTickUnit tick = new NumberTickUnit(yAxisTickCount); axis.setTickUnit(tick); } plot.setRangeAxis(yAxisIndex, axis); plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT); } yAxisIndex++; } plot.mapDatasetToRangeAxis(plotIndex, yAxisIndex - 1); ValueAxis a = plot.getDomainAxis(); if (xAxisName.length() > 0) { a.setLabel(xAxisName); } //We can enable/disable zero on the axis if we have a NumberAxis if (a instanceof NumberAxis) { ((NumberAxis) a).setAutoRangeIncludesZero(zeroOnXScale); } }
From source file:com.jtstand.swing.StatsPanel.java
public JFreeChart getChartDistribution(boolean horizontal) { // System.out.println("Min: " + minValue()); // System.out.println("Max: " + maxValue()); XYIntervalSeriesCollection datasetDistribution = createIntervalXYDatasetDistribution(horizontal); XYSeriesCollection dataset2 = createXYDatasetGauss(horizontal); // create the chart... NumberAxis xAxis = new NumberAxis(getValueString()); xAxis.setAutoRangeIncludesZero(false); // NumberAxis yAxis = new NumberAxis("Distribution"); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(true); //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer = new MyBarRenderer(); XYPlot plot = new XYPlot(datasetDistribution, xAxis, yAxis, renderer); plot.setOrientation(horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping()); chart.setBackgroundPaint((Paint) UIManager.get("Panel.background")); // plot.setBackgroundPaint(Color.white); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); StandardXYItemLabelGenerator itemlabels = new StandardXYItemLabelGenerator(); renderer.setBaseItemLabelGenerator(itemlabels); renderer.setBaseItemLabelsVisible(true); plot.setDataset(1, dataset2);//ww w . j av a2s .com plot.mapDatasetToRangeAxis(1, 1); // ValueAxis domainAxis = plot.getDomainAxis(); //domainAxis.setCategoryLabelPositions(horizontal?CategoryLabelPositions.STANDARD:CategoryLabelPositions.UP_90); ValueAxis axis2 = new NumberAxis("Gaussian"); plot.setRangeAxis(1, axis2); axis2.setVisible(false); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); //renderer2.setShapesVisible(false); //renderer2.setSeriesVisibleInLegend(false); renderer2.setBaseSeriesVisibleInLegend(false); //renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); renderer.setUseYInterval(true); renderer.setBaseSeriesVisibleInLegend(false); /* coloring */ Color c; if (isMultipleCategorization()) { // TreeMap<String, Color> cmap = new TreeMap<String, Color>(); int i = 0; for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) { String groupName = it.next(); c = ChartCategories.getColor(i); for (int j = 0; j < datasetDistribution.getSeriesCount(); j++) { XYIntervalSeries s = datasetDistribution.getSeries(j); if (s.getKey().equals(groupName)) { GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker()); renderer.setSeriesPaint(j, gp); } } for (int j = 0; j < dataset2.getSeriesCount(); j++) { XYSeries s = dataset2.getSeries(j); if (s.getKey().equals(groupName)) { renderer2.setSeriesPaint(j, c); renderer2.setSeriesShapesVisible(j, false); renderer2.setSeriesStroke(j, myStroke); } } } c = Color.black; } else { c = ChartCategories.getColor(0); GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker()); renderer.setSeriesPaint(0, gp); } renderer2.setSeriesPaint(0, c); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesStroke(0, myStroke); placeLimitMarkers(plot, false); // renderer.setAutoPopulateSeriesOutlinePaint(true); // renderer.setBaseOutlinePaint(Color.black); // renderer.setSeriesOutlinePaint(0, Color.black, true); // renderer.setDrawBarOutline(true); renderer.setHighlightedItem(0, 0); yAxis.setAutoRange(false); yAxis.setAutoRange(true); xAxis.setRange(leftValue(0), rightValue(numberOfCategories - 1)); chart.setTextAntiAlias(false); return chart; }
From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java
/** * ?jfreechart/* w w w . j a v a 2 s .c o m*/ */ public void initChart() { ts_wppm = new TimeSeries("PPM", Millisecond.class); ts_wppm_zero = new TimeSeries("PPM-Zero", Millisecond.class); ts_flux = new TimeSeries("Flux", Millisecond.class); ts_wvtr = new TimeSeries("WVTR", Millisecond.class); ts_tempcell = new TimeSeries(" Cell Temperature", Millisecond.class); ts_tempambi = new TimeSeries("Ambient Temperature", Millisecond.class); ts_status = new TimeSeries("Status", Millisecond.class); ts_fitting = new TimeSeries("fitting curve1", Millisecond.class); ts_fitting2 = new TimeSeries("fitting curve2", Millisecond.class); trcollection = new TimeSeriesCollection(ts_wppm); trcollection.addSeries(ts_wppm_zero); trcollection.addSeries(ts_wvtr); trcollection.addSeries(ts_fitting2);//ppm trcollection2 = new TimeSeriesCollection(ts_flux); trcollection2.addSeries(ts_fitting);//temp3 trcollection2.addSeries(ts_tempcell); trcollection2.addSeries(ts_tempambi); trcollection2.addSeries(ts_status); // timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1)); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection, true, true, false); XYPlot xyplot = jfreechart.getXYPlot(); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); Font fs = new Font("", Font.BOLD, 14); Font fs2 = new Font("", Font.BOLD, 12); XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0); Color purple = new Color(139, 0, 255); line0render.setSeriesPaint(0, Color.blue); line0render.setSeriesPaint(1, Color.green); line0render.setSeriesPaint(2, Color.red); line0render.setSeriesPaint(3, purple); // line0render.setSeriesPaint(3, Color.ORANGE); XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer(); Color Rosered = new Color(230, 28, 100); line1render.setSeriesPaint(0, Color.orange); line1render.setSeriesPaint(1, Color.yellow); line1render.setSeriesPaint(2, Color.cyan); line1render.setSeriesPaint(3, Rosered); line1render.setBaseShapesVisible(false); xyplot.setRenderer(1, line1render); //?? ValueAxis valueaxis = xyplot.getDomainAxis(); // valueaxis.setLabelFont(fs); // valueaxis.setTickLabelFont(fs2); ValueAxis valueaxis2 = new NumberAxis(""); valueaxis2.setLabelFont(fs); valueaxis2.setTickLabelFont(fs2); xyplot.setRangeAxis(1, valueaxis2); xyplot.setDataset(1, trcollection2); xyplot.mapDatasetToRangeAxis(1, 1); //?? valueaxis.setAutoRange(true); //?? 7days // valueaxis.setFixedAutoRange(604800000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setLabelFont(new Font("", Font.BOLD, 14)); valueaxis.setLabelPaint(line0render.getSeriesPaint(0)); valueaxis2.setLabelPaint(line1render.getSeriesPaint(0)); jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));// jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15)); xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}", new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000"))); xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}", new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000"))); chartPanel = new ChartPanel(jfreechart); initChartMenu(); // chartPanel.getPopupMenu().add(jmenuitem2); // chartPanel.getPopupMenu().getPopupMenuListeners(); chartPanel.setSize(950, 620); chartPanel.setPreferredSize(new Dimension(950, 620)); jPanel_Show.add(chartPanel, BorderLayout.CENTER); }
From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String propertyName, String morani) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);//from w w w . j a v a 2 s. c o m plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairLockedOnData(true); plot.setDomainCrosshairPaint(java.awt.Color.CYAN); plot.setRangeCrosshairPaint(java.awt.Color.CYAN); plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); // 2. Setup Scatter plot // Create the scatter data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(propertyName); // ZScore xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis("lagged " + propertyName); //$NON-NLS-1$ yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot plotRenderer.setBaseToolTipGenerator(plotToolTip); // Set the scatter data, renderer, and axis into plot plot.setDataset(0, getScatterPlotData(features)); plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); // dot // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); plot.setDataset(1, getLinePlotData(crossCenter)); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY))); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend String title = "Moran's I = " + morani; //$NON-NLS-1$ java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(title, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java
/** * Temperaturgraph machen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * /*from ww w .j a va 2s.com*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 02.08.2012 * @param labels * @param thePlot * @param diveList */ private void makeTemperatureGraph(Vector<Integer[]> diveList, XYPlot thePlot, String[] labels) { XYDataset tempDataSet; Color axisColor = new Color(ProjectConst.GRAPH_TEMPERATURE_ACOLOR); Color renderColor = new Color(ProjectConst.GRAPH_TEMPERATURE_RCOLOR); // lg.debug("create temp dataset"); if (showingUnitSystem == savedUnitSystem || showingUnitSystem == ProjectConst.UNITS_DEFAULT) { // Keine nderung norwendig! tempDataSet = createXYDataset(LangStrings.getString("spx42LogGraphPanel.graph.tempScalaTitle"), diveList, ProjectConst.UNITS_DEFAULT, 0, LogDerbyDatabaseUtil.TEMPERATURE); } else { // bitte konvertiere die Einheiten ins gewnschte Format! tempDataSet = createXYDataset(LangStrings.getString("spx42LogGraphPanel.graph.tempScalaTitle"), diveList, showingUnitSystem, 0, LogDerbyDatabaseUtil.TEMPERATURE); } final XYLineAndShapeRenderer lineTemperatureRenderer = new XYLineAndShapeRenderer(true, true); final NumberAxis tempAxis = new NumberAxis( LangStrings.getString("spx42LogGraphPanel.graph.tempAxisTitle") + " " + labels[1]); tempAxis.setLabelPaint(axisColor); tempAxis.setTickLabelPaint(axisColor); tempAxis.setNumberFormatOverride(new DecimalFormat("###.##")); lineTemperatureRenderer.setSeriesPaint(0, renderColor); lineTemperatureRenderer.setSeriesShapesVisible(0, false); lineTemperatureRenderer.setDrawSeriesLineAsPath(true); tempAxis.setAutoRangeIncludesZero(true); thePlot.setRangeAxis(GRAPH_DEPTH, tempAxis); thePlot.mapDatasetToRangeAxis(GRAPH_DEPTH, 0); thePlot.setDataset(GRAPH_TEMPERATURE, tempDataSet); thePlot.setRenderer(GRAPH_TEMPERATURE, lineTemperatureRenderer); }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart actualLabChartRef(String demographicNo, String labType, String identifier, String testName, String patientName, String chartTitle) { org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); ArrayList<Map<String, Serializable>> list = CommonLabTestValues.findValuesForTest(labType, demographicNo, testName, identifier);//from w ww . j a v a 2 s .c o m String typeYAxisName = ""; ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); String typeLegendName = "Lab Value"; typeYAxisName = "type Y"; boolean nameSet = false; TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class); for (Map mdb : list) { if (!nameSet) { typeYAxisName = (String) mdb.get("units"); typeLegendName = (String) mdb.get("testName"); newSeries.setKey(typeLegendName); nameSet = true; } newSeries.addOrUpdate(new Day((Date) mdb.get("collDateDate")), Double.parseDouble("" + mdb.get("result"))); log.debug("RANGE " + mdb.get("range")); if (mdb.get("range") != null) { String range = (String) mdb.get("range"); if (range.indexOf("-") != -1) { String[] sp = range.split("-"); double open = Double.parseDouble(sp[0]); double high = Double.parseDouble(sp[1]); double low = Double.parseDouble(sp[0]); double close = Double.parseDouble(sp[1]); double volume = 1045; dataItems.add(new OHLCDataItem(new Day((Date) mdb.get("collDateDate")).getStart(), open, high, low, close, volume)); } } } dataset.addSeries(newSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true, true, true); XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setAutoRange(true); 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); ValueAxis va = plot.getRangeAxis(); va.setAutoRange(true); XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance() XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}", new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00")); renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairPaint(Color.GRAY); if (renderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer; rend.setBaseShapesVisible(true); rend.setBaseShapesFilled(true); } plot.setRenderer(renderer); if (dataItems != null && dataItems.size() > 0) { OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]); XYDataset referenceRangeDataset = new DefaultOHLCDataset("Normal Reference Range", ohlc); plot.setDataset(1, referenceRangeDataset); plot.mapDatasetToRangeAxis(1, 0); plot.setRenderer(1, new HighLowRenderer()); } return chart; }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
/** * Creates a chart.// w w w . j a v a 2 s . c o m * * @return a chart. */ private JFreeChart createPriceVolumeChart(XYDataset priceDataset, XYDataset volumeDataset) { final String title = getBestStockName(); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); final NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_Price")); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0.00#"); rangeAxis1.setNumberFormatOverride(format); XYPlot plot = new XYPlot(priceDataset, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(0, renderer1); final NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(1.00); // to leave room for price line plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, volumeDataset); plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer2 = new XYBarRenderer(0.20); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); plot.setRenderer(1, renderer2); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis); cplot.add(plot, 1); cplot.setGap(8.0); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true); org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart); // Only do it after applying chart theme. org.yccheok.jstock.charting.Utils.setPriceSeriesPaint(renderer1); org.yccheok.jstock.charting.Utils.setVolumeSeriesPaint(renderer2); // Handle zooming event. chart.addChangeListener(this.getChartChangeListner()); return chart; }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart actualLabChartRefPlusMeds(String demographicNo, String labType, String identifier, String testName, String patientName, String chartTitle, String[] drugs) { org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); ArrayList<Map<String, Serializable>> list = null; MiscUtils.getLogger().debug(/*from www . j a v a2 s . com*/ " lab type >" + labType + "< >" + labType.equals("loinc") + "<" + testName + " " + identifier); if (labType.equals("loinc")) { try { Connection conn = DbConnectionFilter.getThreadLocalDbConnection(); list = CommonLabTestValues.findValuesByLoinc2(demographicNo, identifier, conn); MiscUtils.getLogger().debug("List ->" + list.size()); conn.close(); } catch (Exception ed) { MiscUtils.getLogger().error("Error", ed); } } else { list = CommonLabTestValues.findValuesForTest(labType, demographicNo, testName, identifier); } String typeYAxisName = ""; ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); String typeLegendName = "Lab Value"; typeYAxisName = "type Y"; boolean nameSet = false; TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class); for (Map mdb : list) { if (!nameSet) { typeYAxisName = (String) mdb.get("units"); typeLegendName = (String) mdb.get("testName"); if (typeLegendName == null) { typeLegendName = testName; } newSeries.setKey(typeLegendName); nameSet = true; } newSeries.addOrUpdate(new Day((Date) mdb.get("collDateDate")), Double.parseDouble("" + mdb.get("result"))); log.debug("RANGE " + mdb.get("range")); if (mdb.get("range") != null) { String range = (String) mdb.get("range"); if (range.indexOf("-") != -1) { String[] sp = range.split("-"); double open = Double.parseDouble(sp[0]); double high = Double.parseDouble(sp[1]); double low = Double.parseDouble(sp[0]); double close = Double.parseDouble(sp[1]); double volume = 1045; dataItems.add(new OHLCDataItem(new Day((Date) mdb.get("collDateDate")).getStart(), open, high, low, close, volume)); } } } dataset.addSeries(newSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true, true, true); XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setAutoRange(true); 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); ValueAxis va = plot.getRangeAxis(); va.setAutoRange(true); XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance() XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}", new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00")); renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairPaint(Color.GRAY); if (renderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer; rend.setBaseShapesVisible(true); rend.setBaseShapesFilled(true); } plot.setRenderer(renderer); if (dataItems != null && dataItems.size() > 0) { OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]); XYDataset referenceRangeDataset = new DefaultOHLCDataset("Normal Reference Range", ohlc); plot.setDataset(1, referenceRangeDataset); plot.mapDatasetToRangeAxis(1, 0); plot.setRenderer(1, new HighLowRenderer()); } XYTaskDataset drugDataset = getDrugDataSet(demographicNo, drugs); //DateAxis xAxis = new DateAxis("Date/Time"); //DateAxis xAxis = plot.getRangeAxis(); 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(plot); cplot.add(xyplot); /////// chart = new JFreeChart(chartTitle, cplot); chart.setBackgroundPaint(Color.white); return chart; }
From source file:OAT.ui.BarChartFrame.java
public void addDataset(ChartDataset dataset) { if (dataset == null || dataset.getSeriesCount() == 0) { return;/* w w w. j a v a 2 s . c o m*/ } XYPlot plot = getChart().getXYPlot(); int i = plot.getDatasetCount(); for (int j = 0; j < i; j++) { if (plot.getDataset(j).equals(dataset)) { // System.out.println("eq " + i // + " " + ((ChartDataset) plot.getDataset(j)).getTitle() // + " " + dataset.getTitle()); return; } } plot.setDataset(i, dataset); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); Double[] range = dataset.getAxisRange(); //axis int axisId = 0; if (range != null) { // if (range == null || range.length < 2) { // plot.mapDatasetToRangeAxis(i, 0); // } else { //scan for equal axis range, reuse if found boolean hasSameRange = false; if (range.length > 1) { for (int j = 1; j < plot.getRangeAxisCount(); j++) { Range otherRange = plot.getRangeAxis(j).getRange(); if (otherRange != null && otherRange.getLowerBound() == range[0] && otherRange.getUpperBound() == range[1]) { axisId = j; hasSameRange = true; break; } } } if (!hasSameRange) { NumberAxis newAxis = new NumberAxis(); if (range.length > 1) { newAxis.setAutoRange(false); newAxis.setRange(range[0], range[1]); } if (range.length > 2) { newAxis.setAutoTickUnitSelection(false, false); newAxis.setTickUnit(new NumberTickUnit(range[2])); } newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER); // newAxis.setAxisLinePaint(new Color(100, 0, 0)); // newAxis.setLabelPaint(paints[i][0]); // newAxis.setTickLabelPaint(paints[i][0]); // newAxis.setTickMarkPaint(paints[i][0]); // newAxis.setTickLabelsVisible(true); axisId = plot.getRangeAxisCount(); plot.setRangeAxis(axisId, newAxis, false); plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false); } // plot.mapDatasetToRangeAxis(i, newAxisId); } plot.mapDatasetToRangeAxis(i, axisId); // //renderer XYLineAndShapeRenderer renderer; if (dataset instanceof TradeDataset) { renderer = new TradeRenderer(); for (int j = 0; j < dataset.getSeriesCount(); j++) { renderer.setSeriesLinesVisible(j, false); } } else { Shape shape = Main.defaultShape; Paint[][] seriesPaints; Stroke stroke; if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) { seriesPaints = Main.greyPaints; stroke = Main.dottedStoke; } else { seriesPaints = Main.defaultPaints; stroke = Main.defaultStoke; } renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke); } plot.setRenderer(i, renderer, false); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
private void pushDataAndRendererIntoPlot(XYPlot plot, int rangeAxisIdx, XYItemRenderer renderer, XYDataset dataset) throws ChartPlottimeException { if (dataset != null && renderer != null) { int datasetIdx = plot.getDatasetCount(); if (datasetIdx > 0 && plot.getDataset(datasetIdx - 1) == null) { datasetIdx -= 1;//from ww w .j a v a 2 s. c o m } // push dataset and renderer into plot try { plot.setDataset(datasetIdx, dataset); // if Eclipse states that // dataset might not be // initialized, you did // not consider all // possibilities in the // condition block above } catch (RuntimeException e) { // probably this is because the domain axis contains values less // then zero and the scaling is logarithmic. // The shitty JFreeChart implementation does not throw a proper // exception stating what happened, // but just a RuntimeException with a string, so this is our // best guess: if (isProbablyZeroValuesOnLogScaleException(e)) { throw new ChartPlottimeException("gui.plotter.error.log_axis_contains_zero", "domain axis"); } else { throw e; } } plot.mapDatasetToRangeAxis(datasetIdx, rangeAxisIdx); plot.setRenderer(datasetIdx, renderer); } else { ChartPlottimeException chartPlottimeException = new ChartPlottimeException( new PlotConfigurationError("generic_plotter_error")); throw chartPlottimeException; } }