List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:org.gumtree.vis.hist2d.Hist2D.java
private void createChart() { createXAxis();//from w w w . ja va2 s . c o m createYAxis(); createScaleAxis(); float min = (float) dataset.getZMin(); float max = (float) dataset.getZMax(); PaintScale scale = generateRainbowScale(min, max, ColorScale.Rainbow); createRender(scale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); plot.setDomainPannable(true); plot.setRangePannable(true); chart = new JFreeChart(dataset.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); // chart = new JFreeChart(dataset.getTitle(), plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); PaintScale scaleBar = generateRainbowScale(min, max, ColorScale.Rainbow); PaintScaleLegend legend = createScaleLegend(scaleBar); legend.setSubdivisionCount(ColorScale.DIVISION_COUNT); chart.addSubtitle(legend); chart.setBorderVisible(true); // ChartUtilities.applyCurrentTheme(chart); defaultChartTheme.apply(chart); chart.fireChartChanged(); }
From source file:cs.stats.gui.StatsCharts.java
private ChartPanel createChart(String axisLabel, int type) { int width = (screenSize.width - (screenSize.width / 35)); int height = (int) (screenSize.height - (screenSize.height / (double) 4)); //int width = (screenSize.width - (screenSize.width / 35)) / 2; //int height = (int) (screenSize.height - (screenSize.height / (double) 4)) / 2; lastValue = new double[SUBPLOT_COUNT]; //================= visualise standard chart ========================== CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); lastValue[0] = 100D;//from w w w.java 2 s . c o m TimeSeries timeseries = null; XYPlot xyplot = null; //add new timeseries to modularity row datasets[type] = new TimeSeriesCollection(); NumberAxis numberaxis = new NumberAxis(axisLabel); numberaxis.setAutoRangeIncludesZero(true); //fast StandardXYItemRenderer xyItemRender = new StandardXYItemRenderer(); //original //xyItemRender = new StandardXYItemRenderer(); xyItemRender.setSeriesStroke(0, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(1, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(2, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(3, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(4, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(5, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(6, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(7, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(8, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(9, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); //TODO colours need to be defined statically before the renderer is created! xyplot = new XYPlot(datasets[type], null, numberaxis, xyItemRender); switch (type) { case 0: { xyItemRender.setSeriesPaint(0, Color.BLACK); timeseries = new TimeSeries("Reply rate 1.0", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(1, Color.BLUE); timeseries = new TimeSeries("Reply rate 0.9", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(2, Color.ORANGE); timeseries = new TimeSeries("Reply rate 0.8", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(3, Color.GREEN); timeseries = new TimeSeries("Reply rate 0.7", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(4, Color.MAGENTA); timeseries = new TimeSeries("Reply rate 0.6", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(5, Color.LIGHT_GRAY); timeseries = new TimeSeries("Reply rate 0.5", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(6, Color.YELLOW); timeseries = new TimeSeries("Reply rate 0.4", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); // xyItemRender.setSeriesPaint(7, Color.PINK); // timeseries = new TimeSeries("Reply rate 0.3", org.jfree.data.time.Hour.class); // datasets[type].addSeries(timeseries); // // xyItemRender.setSeriesPaint(8, Color.RED); // timeseries = new TimeSeries("Reply rate 0.2", org.jfree.data.time.Hour.class); // datasets[type].addSeries(timeseries); // // xyItemRender.setSeriesPaint(9, Color.CYAN); // timeseries = new TimeSeries("Reply rate 0.1", org.jfree.data.time.Hour.class); // datasets[type].addSeries(timeseries); } break; case 1: { xyItemRender.setSeriesPaint(0, Color.BLACK); timeseries = new TimeSeries("0% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(1, Color.BLUE); timeseries = new TimeSeries("1% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(2, Color.ORANGE); timeseries = new TimeSeries("2% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(3, Color.GREEN); timeseries = new TimeSeries("3% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(4, Color.MAGENTA); timeseries = new TimeSeries("3.5% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(5, Color.LIGHT_GRAY); timeseries = new TimeSeries("4% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(6, Color.YELLOW); timeseries = new TimeSeries("4.5% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(7, Color.PINK); timeseries = new TimeSeries("5% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(8, Color.RED); timeseries = new TimeSeries("5.5% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(9, Color.CYAN); timeseries = new TimeSeries("6% of community users removed", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 2: { xyItemRender.setSeriesPaint(0, Color.GRAY); timeseries = new TimeSeries("Average number of thread replies (per hour)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 3: { xyItemRender.setSeriesPaint(0, Color.GREEN); timeseries = new TimeSeries("New thread arrival activity change (%)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(1, Color.BLUE); timeseries = new TimeSeries("Thread reply activity change (%)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 4: { xyItemRender.setSeriesPaint(0, Color.GREEN); timeseries = new TimeSeries("Mean thread aswer time", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; } NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setTickUnit(new NumberTickUnit(0.1)); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.add(xyplot); ChartPanel chart = null; switch (type) { case 0: { jfreechart1 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart1.getSubtitle(0); //set legend fonts jfreechart1.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart1.setBorderPaint(Color.black); jfreechart1.setBorderVisible(true); jfreechart1.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis1 = combineddomainxyplot.getDomainAxis(); dateAxis1 = (DateAxis) valueAxis1; dateAxis1.setTickUnit(new DateTickUnit(1, 1)); if (scope1 == 0) { valueAxis1.setAutoRange(true); } else { valueAxis1.setFixedAutoRange(scope1); } chart = new ChartPanel(jfreechart1); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); //chart.add(buildPlotDisplayManagementPanel(valueAxis1, dateAxis1, ddlScope1)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart1.setAntiAlias(false); } break; case 1: { jfreechart2 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart2.getSubtitle(0); //set legend fonts jfreechart2.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart2.setBorderPaint(Color.black); jfreechart2.setBorderVisible(true); jfreechart2.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis2 = combineddomainxyplot.getDomainAxis(); dateAxis2 = (DateAxis) valueAxis2; dateAxis2.setTickUnit(new DateTickUnit(1, 1)); if (scope2 == 0) { valueAxis2.setAutoRange(true); } else { valueAxis2.setFixedAutoRange(scope2); } chart = new ChartPanel(jfreechart2); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart2.setAntiAlias(false); } break; case 2: { jfreechart3 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart3.getSubtitle(0); //set legend fonts jfreechart3.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart3.setBorderPaint(Color.black); jfreechart3.setBorderVisible(true); jfreechart3.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis3 = combineddomainxyplot.getDomainAxis(); dateAxis3 = (DateAxis) valueAxis3; if (scope3 == 0) { valueAxis3.setAutoRange(true); } else { valueAxis3.setFixedAutoRange(scope3); } chart = new ChartPanel(jfreechart3); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis3, dateAxis3, ddlScope3)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart3.setAntiAlias(false); } break; case 3: { jfreechart4 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart4.getSubtitle(0); //set legend fonts jfreechart4.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart4.setBorderPaint(Color.black); jfreechart4.setBorderVisible(true); jfreechart4.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis4 = combineddomainxyplot.getDomainAxis(); dateAxis4 = (DateAxis) valueAxis4; if (scope4 == 0) { valueAxis4.setAutoRange(true); } else { valueAxis4.setFixedAutoRange(scope4); } chart = new ChartPanel(jfreechart4); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis4, dateAxis4, ddlScope4)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart4.setAntiAlias(false); } break; case 4: { jfreechart5 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart5.getSubtitle(0); //set legend fonts jfreechart5.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart5.setBorderPaint(Color.black); jfreechart5.setBorderVisible(true); jfreechart5.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis5 = combineddomainxyplot.getDomainAxis(); dateAxis5 = (DateAxis) valueAxis5; if (scope5 == 0) { valueAxis5.setAutoRange(true); } else { valueAxis5.setFixedAutoRange(scope5); } chart = new ChartPanel(jfreechart5); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis5, dateAxis5, ddlScope5)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart5.setAntiAlias(false); } break; } return chart; }
From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.Chromatogram2DViewTopComponent.java
private XYPlot createPlot(IChromatogramDescriptor chromatogram, ADataset2D<IChromatogram2D, IScan2D> ds, PaintScale ps) {/* ww w.j ava 2s. c o m*/ XYNoBlockRenderer xybr = new XYNoBlockRenderer(); xybr.setPaintScale(ps); try { double modulationTime = chromatogram.getChromatogram().getParent().getChild("modulation_time") .getArray().getDouble(0); double scanRate = chromatogram.getChromatogram().getParent().getChild("scan_rate").getArray() .getDouble(0); xybr.setDefaultEntityRadius(10);//Math.max(1, (int)(modulationTime / scanRate))); xybr.setEntityThreshold(ds.getMinZ()); xybr.setBlockWidth(modulationTime); xybr.setBlockAnchor(RectangleAnchor.CENTER); double spm = modulationTime * scanRate; double scanDuration = modulationTime / spm; xybr.setBlockHeight(scanDuration); } catch (ResourceNotAvailableException rnae) { } RTUnit rtUnit = RTUnit.SECONDS; xybr.setToolTipGenerator( new StandardXYZToolTipGenerator("{0}: @({1}, {2}) = {3}", DecimalFormat.getNumberInstance(), DecimalFormat.getNumberInstance(), DecimalFormat.getNumberInstance())); NumberAxis rt1 = new NumberAxis("RT1 [" + rtUnit.name().toLowerCase() + "]"); NumberAxis rt2 = new NumberAxis("RT2 [" + rtUnit.name().toLowerCase() + "]"); rt1.setAutoRange(false); rt1.setLowerBound(ds.getMinX()); rt1.setUpperBound(ds.getMaxX()); rt1.setRangeWithMargins(ds.getMinX(), ds.getMaxX()); rt2.setFixedAutoRange(ds.getMaxX() - ds.getMinX()); rt2.setAutoRange(false); rt2.setLowerBound(ds.getMinY()); rt2.setUpperBound(ds.getMaxY()); rt2.setFixedAutoRange(ds.getMaxY() - ds.getMinY()); rt2.setRangeWithMargins(ds.getMinY(), ds.getMaxY()); XYPlot heatmapPlot = new XYPlot(ds, rt1, rt2, xybr); heatmapPlot.setDomainPannable(true); heatmapPlot.setRangePannable(true); return heatmapPlot; }
From source file:graficoyoutube.Grafico.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: ChartPanel panel;/*from w w w. ja v a 2 s .c o m*/ JFreeChart chart = null; if (l.isSelected()) { //Graficas de Lineas int validar = 1; XYSplineRenderer renderer = new XYSplineRenderer(); XYSeriesCollection dataset = new XYSeriesCollection(); ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos"); XYPlot plot; lineas.removeAll(); try { for (int fila = 0; fila <= datos.getRowCount(); fila++) { serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))), Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1)))); //JOptionPane.showMessageDialog(this,datos.getValueAt(fila, 0)+" ,"+ datos.getValueAt(fila, 1)); } } catch (Exception ex) { validar = 0; JOptionPane.showMessageDialog(this, ex.getMessage() + "\n" + validar); } if (validar == 1) { dataset.addSeries(serie); x.setLabel("Eje X"); y.setLabel("Eje Y"); plot = new XYPlot(dataset, x, y, renderer); chart = new JFreeChart(plot); chart.setTitle("Grafico de Lineas YouTube"); } else { JOptionPane.showMessageDialog(this, "Debe llenar la tabla con datos numericos"); } } else { if (b.isSelected()) { //Grafico de Barras DefaultCategoryDataset data = new DefaultCategoryDataset(); String producto1 = "Sopas"; String producto2 = "Soda"; String dia1 = "Dia 1"; String dia2 = "Dia 2"; String dia3 = "Dia 3"; String dia4 = "Dia 4"; data.addValue(18, producto1, dia1); data.addValue(15, producto1, dia2); data.addValue(14, producto1, dia3); data.addValue(1, producto1, dia4); data.addValue(50, producto2, dia1); data.addValue(45, producto2, dia2); data.addValue(31, producto2, dia3); data.addValue(10, producto2, dia4); chart = ChartFactory.createBarChart("Grafico de Barras YouTube", "Dia", "Cantidad", data, PlotOrientation.HORIZONTAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); } else { //Grafico de Pastel DefaultPieDataset data = new DefaultKeyedValuesDataset(); data.setValue("Categoria 1", 20); data.setValue("Categoria 2", 60); data.setValue("Categoria 3", 20); chart = ChartFactory.createPieChart3D("Grafico de Pastel", data, true, true, true); } } panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 400); if (l.isSelected()) { //Lineas lineas.add(panel); lineas.repaint(); } else { if (b.isSelected()) { barras.add(panel); barras.repaint(); } else { pastel.add(panel); pastel.repaint(); } } }
From source file:ecg.ecgshow.ECGShowUI.java
private void createPressureData(long timeZone) { PressureData = new JPanel(); PressuredateAxises = new DateAxis[1]; SystolicPressureSeries = new TimeSeries[2]; DiastolicPressureSeries = new TimeSeries[2]; TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); SystolicPressureSeries[0] = new TimeSeries(""); SystolicPressureSeries[0].setMaximumItemAge(timeZone); SystolicPressureSeries[0].setMaximumItemCount(500); SystolicPressureSeries[1] = new TimeSeries(""); SystolicPressureSeries[1].setMaximumItemAge(timeZone); SystolicPressureSeries[1].setMaximumItemCount(2); timeseriescollection.addSeries(SystolicPressureSeries[0]); timeseriescollection.addSeries(SystolicPressureSeries[1]); PressuredateAxises[0] = new DateAxis(""); PressuredateAxises[0].setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016))); PressuredateAxises[0].setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018))); PressuredateAxises[0].setTickLabelsVisible(true); PressuredateAxises[0].setVisible(false); DiastolicPressureSeries[0] = new TimeSeries(""); DiastolicPressureSeries[0].setMaximumItemAge(timeZone); DiastolicPressureSeries[0].setMaximumItemCount(500); DiastolicPressureSeries[1] = new TimeSeries(""); DiastolicPressureSeries[1].setMaximumItemAge(timeZone); DiastolicPressureSeries[1].setMaximumItemCount(2); timeseriescollection.addSeries(DiastolicPressureSeries[0]); timeseriescollection.addSeries(DiastolicPressureSeries[1]); NumberAxis numberaxis = new NumberAxis("Pressure"); numberaxis.setTickLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.016))); numberaxis.setLabelFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.018))); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setVisible(false);//from w w w .ja v a2s .c o m numberaxis.setLowerBound(0D); numberaxis.setUpperBound(200D); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.GREEN); // xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(2)); // xylineandshaperenderer.setSeriesPaint(1, Color.LIGHT_GRAY); // xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(5)); xylineandshaperenderer.setSeriesPaint(2, Color.ORANGE); // xylineandshaperenderer.setSeriesStroke(2, new BasicStroke(2)); // xylineandshaperenderer.setSeriesPaint(3, Color.LIGHT_GRAY); // xylineandshaperenderer.setSeriesStroke(3, new BasicStroke(5)); //XYPlot xyplot = new XYPlot(timeseriescollection, PressuredateAxises[0], numberaxis, xylineandshaperenderer); XYPlot xyplot = new XYPlot(timeseriescollection, dateAxises[0], numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.LIGHT_GRAY); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setBackgroundPaint(Color.BLACK); JFreeChart jfreechart = new JFreeChart(xyplot); jfreechart.setBackgroundPaint(new Color(237, 237, 237));//? jfreechart.getLegend().setVisible(false); ChartPanel chartpanel = new ChartPanel(jfreechart, (int) (WIDTH * 0.155), (int) (HEIGHT * 0.18), 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, true, false, false); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0) //??0 , BorderFactory.createEmptyBorder() //???? )); chartpanel.setMouseZoomable(false); PressureData.add(chartpanel); }
From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java
private JFreeChart createChart(final Expression aExpression) { if (aExpression instanceof BarLineChartExpression) { final CategoryAxis catAxis = new CategoryAxis("Category");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final CategoryPlot plot = new CategoryPlot(createDataset(), catAxis, barsAxis, new BarRenderer()); plot.setRenderer(1, new LineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("Bar Line Chart", plot); }//from w ww .ja v a2s .com if (aExpression instanceof RingChartExpression) { return ChartFactory.createRingChart("Ring Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof AreaChartExpression) { return ChartFactory.createAreaChart("Area Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof BarChartExpression) { return ChartFactory.createBarChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof LineChartExpression) { return ChartFactory.createLineChart("Line Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof MultiPieChartExpression) { return ChartFactory.createMultiplePieChart("Multi Pie Chart", createDataset(), TableOrder.BY_COLUMN, true, false, false);// NON-NLS } if (aExpression instanceof PieChartExpression) { return ChartFactory.createPieChart("Pie Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof WaterfallChartExpressions) { return ChartFactory.createWaterfallChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.HORIZONTAL, true, false, false);// NON-NLS } if (aExpression instanceof BubbleChartExpression) { return ChartFactory.createBubbleChart("Bubble Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ExtendedXYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ScatterPlotChartExpression) { return ChartFactory.createScatterPlot("Scatter Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYAreaLineChartExpression) { final NumberAxis catAxis = new NumberAxis("Range");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final XYPlot plot = new XYPlot(createXYZDataset(), catAxis, barsAxis, new XYAreaRenderer()); plot.setRenderer(1, new XYLineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createXYZDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("XY Area Line Chart", plot);// NON-NLS } if (aExpression instanceof XYAreaChartExpression) { return ChartFactory.createXYAreaChart("XY Area Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYBarChartExpression) { return XYBarChartExpression.createXYBarChart("XY Bar Chart", "X", false, "Y", createIntervalXYDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof RadarChartExpression) { final SpiderWebPlot plot = new SpiderWebPlot(createDataset()); return new JFreeChart("Radar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } if (aExpression instanceof ThermometerChartExpression) { final DefaultValueDataset dataset = new DefaultValueDataset(new Double(65.0)); final ThermometerPlot plot = new ThermometerPlot(dataset); return new JFreeChart("Thermometer Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } return null; }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a SNP block graph for the given parameters. This graph * will show where the intervals do and don't exist. Interval lists * are organized with the X axis label matching the list's key * @param snpIntervals//www . j a va2 s. c om * the blocks * @param startInBasePairs * the x location to start the graph at * @param extentInBasePairs * the extent to use for the graph * @param maximumImageBlockCount * the max # of separate image blocks to use * @param renderAxes * if true render the axes... otherwise dont * @param legendText * the text to use for the legend * @param yAxisText * the text to use for the y axis * @param trueColor * the color to use for true * @param falseColor * the color to use for false * @return * the graph */ public JFreeChart createSnpIntervalGraph( final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs, final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes, final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) { XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs, maximumImageBlockCount); NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)"); xAxis.setAutoRangeIncludesZero(false); xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs)); String[] sortedStrainNames = extractSortedStrainNames(snpIntervals); for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) { LOG.info("Strain Name: " + sortedStrainNames[strainIndex]); } SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); LegendItemCollection items = new LegendItemCollection(); if (legendText != null) { items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0), trueColor, new BasicStroke(), Color.BLACK)); } plot.setFixedLegendItems(items); XYBlockRenderer r = new XYBlockRenderer(); SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor); r.setPaintScale(ps); r.setBlockHeight(1.0); r.setBlockWidth(1.0); plot.setRenderer(r); final JFreeChart chart; if (renderAxes) { chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { xAxis.setVisible(false); yAxis.setVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); chart = new JFreeChart(plot); } chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method createChart./* w ww.j av a 2 s .c om*/ * * @param strategyData * StrategyData * @param title * String * @return JFreeChart */ private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) { DateAxis dateAxis = new DateAxis("Date"); dateAxis.setVerticalTickLabels(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm")); dateAxis.setTickMarkPosition(DateTickMarkPosition.START); NumberAxis priceAxis = new NumberAxis("Price"); priceAxis.setAutoRange(true); priceAxis.setAutoRangeIncludesZero(false); XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis, strategyData.getCandleDataset().getRenderer()); pricePlot.setOrientation(PlotOrientation.VERTICAL); pricePlot.setDomainPannable(true); pricePlot.setRangePannable(true); pricePlot.setDomainCrosshairVisible(true); pricePlot.setDomainCrosshairLockedOnData(true); pricePlot.setRangeCrosshairVisible(true); pricePlot.setRangeCrosshairLockedOnData(true); pricePlot.setRangeGridlinePaint(new Color(204, 204, 204)); pricePlot.setDomainGridlinePaint(new Color(204, 204, 204)); pricePlot.setBackgroundPaint(Color.white); /* * Calculate the number of 15min segments in this trading day. i.e. * 6.5hrs/15min = 26 and there are a total of 96 = one day */ int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime()) / (1000 * 60 * 15); SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, segments15min, (96 - segments15min)); Date startDate = tradingday.getOpen(); Date endDate = tradingday.getClose(); if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) { startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod() .getStart(); startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate); endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0) .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod() .getStart(); endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate); } segmentedTimeline.setStartTime(startDate.getTime()); segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(), tradingday.getClose(), segmentedTimeline)); dateAxis.setTimeline(segmentedTimeline); // Build Combined Plot CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis); mainPlot.add(pricePlot, 4); int axixIndex = 0; int datasetIndex = 0; /* * Change the List of indicators so that the candle dataset is the first * one in the list. The main chart must be plotted first. */ List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0); for (IndicatorDataset item : strategyData.getIndicators()) { if (IndicatorSeries.CandleSeries.equals(item.getType(0))) { indicators.add(item); } } for (IndicatorDataset item : strategyData.getIndicators()) { if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) { indicators.add(item); } } for (int i = 0; i < indicators.size(); i++) { IndicatorDataset indicator = indicators.get(i); if (indicator.getDisplaySeries(0)) { if (indicator.getSubChart(0)) { String axisName = "Price"; if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) { axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol(); } else { org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries .newInstance(indicator.getType(0)); axisName = code.getDisplayName(); } NumberAxis subPlotAxis = new NumberAxis(axisName); subPlotAxis.setAutoRange(true); subPlotAxis.setAutoRangeIncludesZero(false); XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis, indicator.getRenderer()); subPlot.setOrientation(PlotOrientation.VERTICAL); subPlot.setDomainPannable(true); subPlot.setRangePannable(true); subPlot.setDomainCrosshairVisible(true); subPlot.setDomainCrosshairLockedOnData(true); subPlot.setRangeCrosshairVisible(true); subPlot.setRangeCrosshairLockedOnData(true); subPlot.setRangeGridlinePaint(new Color(204, 204, 204)); subPlot.setDomainGridlinePaint(new Color(204, 204, 204)); subPlot.setBackgroundPaint(Color.white); XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator); for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator) .getSeriesCount(); seriesIndex++) { renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex)); } mainPlot.add(subPlot, 1); } else { datasetIndex++; pricePlot.setDataset(datasetIndex, (XYDataset) indicator); if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) { // add secondary axis axixIndex++; final NumberAxis axis2 = new NumberAxis( ((CandleSeries) indicator.getSeries(0)).getSymbol()); axis2.setAutoRange(true); axis2.setAutoRangeIncludesZero(false); pricePlot.setRangeAxis(datasetIndex, axis2); pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT); pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex); pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer()); } else { pricePlot.setRenderer(datasetIndex, indicator.getRenderer()); } XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator); for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator) .getSeriesCount(); seriesIndex++) { renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex)); } } } } JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true); jfreechart.setAntiAlias(false); return jfreechart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYAreaChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setOrientation(orientation);//from w w w .j a v a2 s . co m plot.setForegroundAlpha(0.5f); XYToolTipGenerator tipGenerator = null; if (tooltips) { tipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator)); JFreeChart chart = new JFreeChart("XYArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeScalabilitySummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); NumberAxis yAxis = new NumberAxis("Time spend"); yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }/*from w ww. ja va 2s. c om*/ XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemScale(); long timeMillisSpend = singleBenchmark.getTimeMillisSpend(); series.add((Long) problemScale, (Long) timeMillisSpend); } } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); scalabilitySummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "scalabilitySummary.png"); OutputStream out = null; try { out = new FileOutputStream(scalabilitySummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing scalabilitySummaryFile: " + scalabilitySummaryFile, e); } finally { IOUtils.closeQuietly(out); } }