Example usage for org.jfree.chart.plot XYPlot XYPlot

List of usage examples for org.jfree.chart.plot XYPlot XYPlot

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot XYPlot.

Prototype

public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) 

Source Link

Document

Creates a new plot with the specified dataset, axes and renderer.

Usage

From source file:com.sixrr.metrics.ui.charts.DiffDistributionDialog.java

private JFreeChart createChart(XYDataset dataset) {
    final String title = getTitle();

    final NumberAxis xAxis = new NumberAxis(metricName);
    xAxis.setAutoRangeIncludesZero(false);
    if (metricType.equals(MetricType.Ratio) || metricType.equals(MetricType.RecursiveRatio)) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }//from w w w .j a va  2s. co m
    final NumberAxis yAxis = new NumberAxis("%");
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:net.relet.freimap.LinkInfo.java

public void setFlowProfile(LinkedList<FlowData> lp) {

    XYSeries packets = new XYSeries("packets");
    XYSeries bytes = new XYSeries("bytes");
    XYSeries icmp = new XYSeries("icmp");
    XYSeries tcp = new XYSeries("tcp");
    XYSeries udp = new XYSeries("udp");
    XYSeries other = new XYSeries("other");

    XYSeriesCollection data1 = new XYSeriesCollection(bytes);
    XYSeriesCollection data2 = new XYSeriesCollection(packets);
    XYSeriesCollection data3 = new XYSeriesCollection(icmp);
    data3.addSeries(tcp);// w  w w .ja v a2  s.c  o m
    data3.addSeries(udp);
    data3.addSeries(other);

    //linkChart = ChartFactory.createXYLineChart("packets, bytes\r\nicmp, tcp, udp other", "time", "count", data1, PlotOrientation.VERTICAL, false, false, false);
    ValueAxis domain = new DateAxis();
    ValueAxis range1 = new NumberAxis();
    ValueAxis range2 = new NumberAxis();
    ValueAxis range3 = new NumberAxis();
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domain);
    plot.add(new XYPlot(data2, domain, range1, new XYLineAndShapeRenderer(true, false)));
    plot.add(new XYPlot(data1, domain, range2, new XYLineAndShapeRenderer(true, false)));
    plot.add(new XYPlot(data3, domain, range1, new XYLineAndShapeRenderer(true, false)));
    linkChart = new JFreeChart(plot);
    linkChart.setTitle("");
    sexupLayout(linkChart);

    long min = lp.getFirst().begin, max = lp.getLast().end;

    for (float i = 0.0f; i < 1000.0f; i += 1.0f) {
        long cur = min + (long) ((max - min) * (i / 1000.0));

        long cpackets = 0;
        long cbytes = 0;
        long cicmp = 0;
        long ctcp = 0;
        long cudp = 0;
        long cother = 0;

        Iterator<FlowData> li = lp.iterator();
        while (li.hasNext()) {
            FlowData data = li.next();
            if (data.begin > cur)
                break;
            if (data.end < cur)
                continue;
            cpackets += data.packets;
            cbytes += data.bytes;
            switch (data.protocol) {
            case 1: {
                cicmp += data.packets;
                break;
            }
            case 6: {
                ctcp += data.packets;
                break;
            }
            case 17: {
                cudp += data.packets;
                break;
            }
            default: {
                cother += data.packets;
                break;
            }
            }
        }

        packets.add(cur, cpackets);
        bytes.add(cur, cbytes);
        icmp.add(cur, cicmp);
        tcp.add(cur, ctcp);
        udp.add(cur, cudp);
        other.add(cur, cother);
    }

    status = STATUS_AVAILABLE;
}

From source file:org.jfree.chart.demo.CombinedXYPlotDemo5.java

/**
 * Creates a combined XYPlot chart.// www .  j  a  va 2 s  .c o  m
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create a default chart based on some sample data...
    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);

    JFreeChart chart = null;

    // make a common vertical axis for all the sub-plots
    final NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false); // override default

    // make a horizontally combined plot
    final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);

    // add subplot 1...
    final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null, new StandardXYItemRenderer());
    subplot1.setDomainCrosshairVisible(true);
    subplot1.setRangeCrosshairVisible(true);
    parent.add(subplot1, 1);

    // add subplot 2...
    final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, new StandardXYItemRenderer());
    subplot2.setDomainCrosshairVisible(true);
    subplot2.setRangeCrosshairVisible(true);
    parent.add(subplot2, 1);

    // add subplot 3...
    final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), null, new XYBarRenderer(0.20));
    subplot3.setDomainCrosshairVisible(true);
    subplot3.setRangeCrosshairVisible(true);
    parent.add(subplot3, 1);

    // now make the top level JFreeChart
    chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle("This is a subtitle", 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:net.sf.mzmine.modules.visualization.neutralloss.NeutralLossPlot.java

NeutralLossPlot(NeutralLossVisualizerWindow visualizer, NeutralLossDataSet dataset, Object xAxisType) {

    super(null, true);

    this.visualizer = visualizer;

    setBackground(Color.white);/*from ww  w .j  a  va2s .  c  o  m*/
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
    NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

    // set the X axis (retention time) properties
    NumberAxis xAxis;
    if (xAxisType.equals(NeutralLossParameters.xAxisPrecursor)) {
        xAxis = new NumberAxis("Precursor m/z");
        xAxis.setNumberFormatOverride(mzFormat);
    } else {
        xAxis = new NumberAxis("Retention time");
        xAxis.setNumberFormatOverride(rtFormat);
    }
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);
    xAxis.setAutoRangeIncludesZero(false);

    // set the Y axis (intensity) properties
    NumberAxis yAxis = new NumberAxis("Neutral loss (Da)");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setNumberFormatOverride(mzFormat);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    // set the renderer properties
    defaultRenderer = new NeutralLossDataPointRenderer(false, true);
    defaultRenderer.setTransparency(0.4f);
    setSeriesColorRenderer(0, pointColor, dataPointsShape);
    setSeriesColorRenderer(1, searchPrecursorColor, dataPointsShape2);
    setSeriesColorRenderer(2, searchNeutralLossColor, dataPointsShape2);

    // tooltips
    defaultRenderer.setBaseToolTipGenerator(dataset);

    // set the plot properties
    plot = new XYPlot(dataset, xAxis, yAxis, defaultRenderer);
    plot.setBackgroundPaint(Color.white);
    plot.setRenderer(defaultRenderer);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    // chart properties
    chart = new JFreeChart("", titleFont, plot, false);
    chart.setBackgroundPaint(Color.white);

    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    plot.addRangeMarker(new ValueMarker(0));

    // set focusable state to receive key events
    setFocusable(true);

    // register key handlers
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("SPACE"), visualizer, "SHOW_SPECTRUM");

    // add items to popup menu
    JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();

    JMenuItem highLightPrecursorRange = new JMenuItem("Highlight precursor m/z range...");
    highLightPrecursorRange.addActionListener(visualizer);
    highLightPrecursorRange.setActionCommand("HIGHLIGHT_PRECURSOR");
    popupMenu.add(highLightPrecursorRange);

    JMenuItem highLightNeutralLossRange = new JMenuItem("Highlight neutral loss m/z range...");
    highLightNeutralLossRange.addActionListener(visualizer);
    highLightNeutralLossRange.setActionCommand("HIGHLIGHT_NEUTRALLOSS");
    popupMenu.add(highLightNeutralLossRange);

}

From source file:wsattacker.plugin.dos.dosExtension.chart.ChartObject.java

public JFreeChart createOverlaidChart() {

    // ----------------------------
    // Data and X-Y-Axis - Response Time Testprobes
    // - Y-Achse 0
    final DateAxis yAxis = new DateAxis("Time");
    yAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    // - X-Achse 0
    final NumberAxis xAxis0 = new NumberAxis("Response Time in ms");
    xAxis0.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // xAxis0.setTickUnit( new NumberTickUnit(1) );
    // - dataset//from w ww  .ja va  2s .  c  om
    // - renderer
    final XYDataset dataResponseTimeProbes = createDatasetResponseTime("testprobe");
    final XYLineAndShapeRenderer rendererResponseTimeProbes = new XYLineAndShapeRenderer(); // StandardXYItemRenderer();
                                                                                            // ->
                                                                                            // should
                                                                                            // not
                                                                                            // be
                                                                                            // used
    rendererResponseTimeProbes.setSeriesPaint(0, Color.blue);
    rendererResponseTimeProbes.setSeriesShape(0, new Ellipse2D.Double(-1.5, -1.5, 3.0, 3.0));
    rendererResponseTimeProbes.setSeriesLinesVisible(0, true);
    rendererResponseTimeProbes.setSeriesShapesVisible(0, true);
    rendererResponseTimeProbes.setUseOutlinePaint(false);
    rendererResponseTimeProbes.setSeriesOutlinePaint(0, Color.black);
    rendererResponseTimeProbes.setUseFillPaint(true);
    rendererResponseTimeProbes.setSeriesFillPaint(0, Color.blue);

    // ----------------------------
    // NEW XYPlot (new "Data and X-Y-Axis" from above added as default)
    final XYPlot plot = new XYPlot(dataResponseTimeProbes, yAxis, xAxis0, rendererResponseTimeProbes);

    // ----------------------------
    // Data and Axis 1 - Response time UNtampered
    // - Dataset
    // - Renderer.
    // - Dataset zu X-Axis 0 mappen
    final XYDataset dataResponseTimeUntampered = createDatasetResponseTime("untampered");
    final XYLineAndShapeRenderer rendererResponseTimeUntampered = new XYLineAndShapeRenderer(); // StandardXYItemRenderer();
                                                                                                // ->
                                                                                                // should
                                                                                                // not
                                                                                                // be
                                                                                                // used
    rendererResponseTimeUntampered.setSeriesPaint(0, new Color(0, 161, 4));
    rendererResponseTimeUntampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));
    rendererResponseTimeUntampered.setUseFillPaint(true);
    rendererResponseTimeUntampered.setSeriesFillPaint(0, Color.white);
    rendererResponseTimeUntampered.setUseOutlinePaint(false);
    rendererResponseTimeUntampered.setSeriesOutlinePaint(0, Color.black);
    rendererResponseTimeUntampered.setSeriesToolTipGenerator(0,
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(2, dataResponseTimeUntampered);
    plot.setRenderer(2, rendererResponseTimeUntampered);
    // plot.mapDatasetToRangeAxis(0, 1);

    // ----------------------------
    // Data and Axis - Response time tampered
    // - Dataset
    // - Renderer
    // - Dataset zu X-Axis 2 mappen
    final XYDataset dataResponseTimeTampered = createDatasetResponseTime("tampered");
    XYLineAndShapeRenderer rendererResponseTimeTampered = new XYLineAndShapeRenderer(); // XYSplineRenderer();
    rendererResponseTimeTampered.setSeriesPaint(0, new Color(189, 0, 0));
    rendererResponseTimeTampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));// (-2.5, -2.5, 6.0,
                                                                                           // 6.0) );
    rendererResponseTimeTampered.setUseFillPaint(true);
    rendererResponseTimeTampered.setSeriesFillPaint(0, Color.white);
    rendererResponseTimeTampered.setUseOutlinePaint(false);
    rendererResponseTimeTampered.setSeriesOutlinePaint(0, Color.black);
    plot.setDataset(3, dataResponseTimeTampered);
    plot.setRenderer(3, rendererResponseTimeTampered);
    // plot.mapDatasetToRangeAxis(0, 2);

    // ----------------------------
    // Data and X-Axis - Number Requests UNtampered
    // - X-Axis Number Requests
    final NumberAxis xAxis1 = new NumberAxis(
            "Number Requests Per Interval (" + (model.getIntervalLengthReport() / 1000) + " sec)");
    xAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // xAxis1.setTickUnit( new NumberTickUnit(2) );
    plot.setRangeAxis(1, xAxis1);
    // - Dataset
    // - Renderer
    final IntervalXYDataset dataNumberRequestsUntampered = createDatasetNumberRequestsUntampered();
    final XYBarRenderer rendererNumberRequestsUntampered = new XYBarRenderer(0.2);
    rendererNumberRequestsUntampered.setShadowVisible(false);
    rendererNumberRequestsUntampered.setBarPainter(new StandardXYBarPainter());
    rendererNumberRequestsUntampered.setSeriesPaint(0, new Color(128, 255, 128));
    plot.setDataset(4, dataNumberRequestsUntampered);
    plot.setRenderer(4, rendererNumberRequestsUntampered);
    plot.mapDatasetToRangeAxis(4, 1);

    // -------------------------------
    // Data - Number Requests tampered
    // - Dataset
    // - Renderer
    final IntervalXYDataset dataNumberRequestsTampered = createDatasetNumberRequestsTampered();
    final XYBarRenderer rendererBarNumberRequestsTampered = new XYBarRenderer(0.2);
    rendererBarNumberRequestsTampered.setShadowVisible(false);
    rendererBarNumberRequestsTampered.setBarPainter(new StandardXYBarPainter());
    rendererBarNumberRequestsTampered.setSeriesPaint(0, new Color(255, 148, 148));
    plot.setDataset(5, dataNumberRequestsTampered);
    plot.setRenderer(5, rendererBarNumberRequestsTampered);
    plot.mapDatasetToRangeAxis(5, 1);

    // -------------------------
    // Other formating stuff
    // - add annotations
    // final double x = new Day(9, SerialDate.MARCH,
    // 2002).getMiddleMillisecond();
    // final XYTextAnnotation annotation = new
    // XYTextAnnotation("Anmerkung zu Datenpunkt", x, 1000.0);
    // annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    // plot.addAnnotation(annotation);

    // -------------------------
    // Create custom LegendTitles
    // Legend Row 1
    LegendTitle legendL1 = new LegendTitle(plot.getRenderer(0));
    legendL1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL1.setBorder(0, 0, 0, 0);
    LegendTitle legendR1 = new LegendTitle(plot.getRenderer(4));
    legendR1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendR1.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.setBorder(0, 0, 0, 0);
    blockcontainer.add(legendL1, RectangleEdge.LEFT);
    blockcontainer.add(legendR1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle1 = new CompositeTitle(blockcontainer);
    compositetitle1.setPosition(RectangleEdge.BOTTOM);
    // Legend Row 2
    LegendTitle legendL2 = new LegendTitle(plot.getRenderer(2));
    legendL2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL2.setBorder(0, 0, 0, 0);
    LegendTitle legendR2 = new LegendTitle(plot.getRenderer(5));
    legendR2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendR2.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer2 = new BlockContainer(new BorderArrangement());
    blockcontainer2.setBorder(0, 0, 0, 0);
    blockcontainer2.add(legendL2, RectangleEdge.LEFT);
    blockcontainer2.add(legendR2, RectangleEdge.RIGHT);
    blockcontainer2.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle2 = new CompositeTitle(blockcontainer2);
    compositetitle2.setPosition(RectangleEdge.BOTTOM);
    // Legend Row 3
    LegendTitle legendL3 = new LegendTitle(plot.getRenderer(3));
    legendL3.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL3.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer3 = new BlockContainer(new BorderArrangement());
    blockcontainer3.setBorder(0, 0, 0, 0);
    blockcontainer3.add(legendL3, RectangleEdge.LEFT);
    blockcontainer3.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle3 = new CompositeTitle(blockcontainer3);
    compositetitle3.setPosition(RectangleEdge.BOTTOM);

    // -------------------------
    // create Chart
    // - return a new chart containing the overlaid plot...
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart jFreeChart = new JFreeChart(model.getAttackName() + " - Response Time Plot", // Roundtrip Time Plot
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    // Add new legend boxes + format
    jFreeChart.addSubtitle(compositetitle1);
    jFreeChart.addSubtitle(compositetitle2);
    jFreeChart.addSubtitle(compositetitle3);

    // Surpress old Legends
    LegendTitle legendee2 = jFreeChart.getLegend(0);
    legendee2.setVisible(false);

    return jFreeChart;
}

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

@Override
public void run() {
    CSV2TableLoader tl = new CSV2TableLoader(this.ph, this.is);

    DefaultTableModel dtm;//from w ww.  j  a v a 2  s. c  o m
    try {
        dtm = tl.call();
        if (this.mode == CHART.XY) {
            XYSeriesCollection cd = new XYSeriesCollection();
            for (int j = 0; j < dtm.getColumnCount(); j++) {
                XYSeries xys = new XYSeries(dtm.getColumnName(j));
                for (int i = 0; i < dtm.getRowCount(); i++) {
                    Object o = dtm.getValueAt(i, j);
                    try {
                        double d = Double.parseDouble(o.toString());
                        xys.add(i, d);
                        Logger.getLogger(getClass().getName()).log(Level.INFO, "Adding {0} {1} {2}",
                                new Object[] { i, d, dtm.getColumnName(j) });
                    } catch (Exception e) {
                    }
                }
                cd.addSeries(xys);
            }
            XYLineAndShapeRenderer d = new XYLineAndShapeRenderer(true, false);
            XYPlot xyp = new XYPlot(cd, new NumberAxis("category"), new NumberAxis("value"), d);

            JFreeChart jfc = new JFreeChart(this.title, xyp);
            jtc.setChart(jfc);
            Logger.getLogger(getClass().getName()).info("creating chart done");
        } else if (this.mode == CHART.MATRIX) {
            DefaultXYZDataset cd = new DefaultXYZDataset();
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Name of column 0: {0}",
                    dtm.getColumnName(0));
            if (dtm.getColumnName(0).isEmpty()) {
                Logger.getLogger(getClass().getName()).info("Removing column 0");
                dtm = removeColumn(dtm, 0);
            }
            if (dtm.getColumnName(dtm.getColumnCount() - 1).equalsIgnoreCase("filename")) {
                dtm = removeColumn(dtm, dtm.getColumnCount() - 1);
            }
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {
                    sb.append(dtm.getValueAt(i, j) + " ");
                }
                sb.append("\n");
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Table before sorting: {0}", sb.toString());
            //                dtm = sort(dtm);
            StringBuilder sb2 = new StringBuilder();
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {
                    sb2.append(dtm.getValueAt(i, j) + " ");
                }
                sb2.append("\n");
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Table after sorting: {0}", sb2.toString());
            int rows = dtm.getRowCount();
            int columns = dtm.getColumnCount();
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Storing {0} * {1} elements, {2} total!",
                    new Object[] { columns, rows, rows * columns });
            double[][] data = new double[3][(columns * rows)];
            ArrayDouble.D1 dt = new ArrayDouble.D1((columns) * rows);
            double min = Double.POSITIVE_INFINITY;
            double max = Double.NEGATIVE_INFINITY;
            EvalTools.eqI(rows, columns, this);
            int k = 0;
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    Object o = dtm.getValueAt(i, j);
                    try {
                        double d = Double.parseDouble(o.toString());
                        if (d < min) {
                            min = d;
                        }
                        if (d > max) {
                            max = d;
                        }
                        data[0][k] = (double) i;
                        data[1][k] = (double) j;
                        data[2][k] = d;
                        dt.set(k, d);
                        k++;
                        //System.out.println("Adding "+i+" "+d+" "+dtm.getColumnName(j));
                    } catch (Exception e) {
                    }
                }
                //cd.addSeries(xys);
            }
            cd.addSeries(this.title, data);
            XYBlockRenderer xyb = new XYBlockRenderer();
            GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max,
                    ImageTools
                            .rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv")));

            xyb.setPaintScale(ps);
            final String[] colnames = new String[dtm.getColumnCount()];
            for (int i = 0; i < colnames.length; i++) {
                colnames[i] = dtm.getColumnName(i);
            }
            NumberAxis na1 = new SymbolAxis("category", colnames);
            na1.setVerticalTickLabels(false);
            NumberAxis na2 = new SymbolAxis("category", colnames);
            na1.setVerticalTickLabels(true);
            XYPlot xyp = new XYPlot(cd, na1, na2, xyb);
            xyb.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {

                @Override
                public String generateToolTip(XYDataset xyd, int i, int i1) {
                    return "[" + colnames[xyd.getX(i, i1).intValue()] + ":"
                            + colnames[xyd.getY(i, i1).intValue()] + "] = "
                            + ((XYZDataset) xyd).getZValue(i, i1) + "";
                }
            });

            JFreeChart jfc = new JFreeChart(this.title, xyp);
            NumberAxis values = new NumberAxis("value");
            values.setAutoRange(false);
            values.setRangeWithMargins(min, max);
            PaintScaleLegend psl = new PaintScaleLegend(ps, values);
            psl.setBackgroundPaint(jfc.getBackgroundPaint());
            jfc.addSubtitle(psl);
            psl.setStripWidth(50);
            psl.setPadding(20, 20, 20, 20);
            psl.setHeight(200);
            psl.setPosition(RectangleEdge.RIGHT);
            jtc.setChart(jfc);
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }

    ph.finish();
}

From source file:OverlaidXYPlotDemo2.java

/**
 * Creates an overlaid chart./*  w w  w  .  j a v a2 s.c  o  m*/
 *
 * @return The chart.
 */
private JFreeChart createOverlaidChart() {

    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    final ValueAxis rangeAxis = new NumberAxis("Value");

    // create plot...
    final IntervalXYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
    final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond();
    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);

    final ValueAxis rangeAxis2 = new NumberAxis("Value 2");
    plot.setRangeAxis(1, rangeAxis2);

    // create subplot 2...
    final XYDataset data2A = createDataset2A();
    final XYItemRenderer renderer2A = new StandardXYItemRenderer();
    renderer2A.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, data2A);
    plot.setRenderer(1, renderer2A);

    final XYDataset data2B = createDataset2B();
    plot.setDataset(2, data2B);
    plot.setRenderer(2, new StandardXYItemRenderer());
    plot.mapDatasetToRangeAxis(2, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:genj.chart.Chart.java

/**
 * Constructor for a chart with x/y series of data shown on a 2d pane
 * as one plot per series. Note: The difference between this and
 * the first constructor is that of indexed series (where all x-values
 * are shared indexes) and arbitrary series.
 * @param title the title of the chart/*from ww w .  java 2 s .com*/
 * @param labelAxisX a label for the x-axis
 * @param labelAxisY a label for the y-axis
 * @param series one or more x/y series to show
 * @param format a number format to use for x-values
 * @param shapes whether to show little shape indicators for each x/y pair additionally to the plot
 */
public Chart(String title, String labelAxisX, String labelAxisY, XYSeries[] series, NumberFormat format,
        boolean shapes) {

    // prepare chart setup
    NumberAxis xAxis = new NumberAxis(labelAxisX);
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis(labelAxisY);
    yAxis.setNumberFormatOverride(format);

    XYItemRenderer renderer = new StandardXYItemRenderer(
            shapes ? StandardXYItemRenderer.SHAPES_AND_LINES : StandardXYItemRenderer.LINES);

    XYPlot plot = new XYPlot(XYSeries.toXYDataset(series), xAxis, yAxis, renderer);

    // init
    init(title, plot, true);

    // done
}

From source file:org.jfree.chart.demo.CombinedTimeSeriesDemo1.java

public static JPanel createDemoPanel() {
    TimeSeries timeseries = new TimeSeries("Annual");
    timeseries.add(new Year(1998), 80D);
    timeseries.add(new Year(1999), 85D);
    timeseries.add(new Year(2000), 87.599999999999994D);
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(timeseries);
    TimeSeries timeseries1 = new TimeSeries("Monthly A");
    timeseries1.add(new Month(7, 2000), 85.799999999999997D);
    timeseries1.add(new Month(8, 2000), 85.799999999999997D);
    timeseries1.add(new Month(9, 2000), 85.799999999999997D);
    timeseries1.add(new Month(10, 2000), 86.5D);
    timeseries1.add(new Month(11, 2000), 86.5D);
    timeseries1.add(new Month(12, 2000), 86.5D);
    timeseries1.add(new Month(1, 2001), 87.700000000000003D);
    timeseries1.add(new Month(2, 2001), 87.700000000000003D);
    timeseries1.add(new Month(3, 2001), 87.700000000000003D);
    timeseries1.add(new Month(4, 2001), 88.5D);
    timeseries1.add(new Month(5, 2001), 88.5D);
    timeseries1.add(new Month(6, 2001), 88.5D);
    timeseries1.add(new Month(7, 2001), 90D);
    timeseries1.add(new Month(8, 2001), 90D);
    timeseries1.add(new Month(9, 2001), 90D);
    timeseries1.add(new Month(10, 2001), 90D);
    timeseries1.add(new Month(11, 2001), 90D);
    timeseries1.add(new Month(12, 2001), 90D);
    timeseries1.add(new Month(1, 2002), 90D);
    timeseries1.add(new Month(2, 2002), 90D);
    timeseries1.add(new Month(3, 2002), 90D);
    timeseries1.add(new Month(4, 2002), 90D);
    timeseries1.add(new Month(5, 2002), 90D);
    timeseries1.add(new Month(6, 2002), 90D);
    TimeSeries timeseries2 = new TimeSeries("Monthly B");
    timeseries2.add(new Month(7, 2000), 83.799999999999997D);
    timeseries2.add(new Month(8, 2000), 83.799999999999997D);
    timeseries2.add(new Month(9, 2000), 83.799999999999997D);
    timeseries2.add(new Month(10, 2000), 84.5D);
    timeseries2.add(new Month(11, 2000), 84.5D);
    timeseries2.add(new Month(12, 2000), 84.5D);
    timeseries2.add(new Month(1, 2001), 85.700000000000003D);
    timeseries2.add(new Month(2, 2001), 85.700000000000003D);
    timeseries2.add(new Month(3, 2001), 85.700000000000003D);
    timeseries2.add(new Month(4, 2001), 86.5D);
    timeseries2.add(new Month(5, 2001), 86.5D);
    timeseries2.add(new Month(6, 2001), 86.5D);
    timeseries2.add(new Month(7, 2001), 88D);
    timeseries2.add(new Month(8, 2001), 88D);
    timeseries2.add(new Month(9, 2001), 88D);
    timeseries2.add(new Month(10, 2001), 88D);
    timeseries2.add(new Month(11, 2001), 88D);
    timeseries2.add(new Month(12, 2001), 88D);
    timeseries2.add(new Month(1, 2002), 88D);
    timeseries2.add(new Month(2, 2002), 88D);
    timeseries2.add(new Month(3, 2002), 88D);
    timeseries2.add(new Month(4, 2002), 88D);
    timeseries2.add(new Month(5, 2002), 88D);
    timeseries2.add(new Month(6, 2002), 88D);
    TimeSeriesCollection dataset21 = new TimeSeriesCollection();
    dataset21.addSeries(timeseries1);// w w w  .  j a  va 2 s.  com
    dataset21.addSeries(timeseries2);
    TimeSeries timeseries3 = new TimeSeries("XXX");
    timeseries3.add(new Month(7, 2000), 81.5D);
    timeseries3.add(new Month(8, 2000), 86D);
    timeseries3.add(new Month(9, 2000), 82D);
    timeseries3.add(new Month(10, 2000), 89.5D);
    timeseries3.add(new Month(11, 2000), 88D);
    timeseries3.add(new Month(12, 2000), 88D);
    timeseries3.add(new Month(1, 2001), 90D);
    timeseries3.add(new Month(2, 2001), 89.5D);
    timeseries3.add(new Month(3, 2001), 90.200000000000003D);
    timeseries3.add(new Month(4, 2001), 90.599999999999994D);
    timeseries3.add(new Month(5, 2001), 87.5D);
    timeseries3.add(new Month(6, 2001), 91D);
    timeseries3.add(new Month(7, 2001), 89.700000000000003D);
    timeseries3.add(new Month(8, 2001), 87D);
    timeseries3.add(new Month(9, 2001), 91.200000000000003D);
    timeseries3.add(new Month(10, 2001), 84D);
    timeseries3.add(new Month(11, 2001), 90D);
    timeseries3.add(new Month(12, 2001), 92D);
    TimeSeriesCollection dataset22 = new TimeSeriesCollection(timeseries3);
    //
    XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0.00")));
    XYPlot plot1 = new XYPlot(dataset1, new DateAxis("Date"), null, renderer1);
    //
    XYAreaRenderer renderer21 = new XYAreaRenderer();
    XYPlot plot2 = new XYPlot(dataset21, new DateAxis("Date"), null, renderer21);
    StandardXYItemRenderer renderer22 = new StandardXYItemRenderer(3);
    renderer22.setBaseShapesFilled(true);
    plot2.setDataset(1, dataset22);
    plot2.setRenderer(1, renderer22);
    plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    //
    NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false);
    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(valueAxis);
    combinedPlot.add(plot1, 1);
    combinedPlot.add(plot2, 4);
    //chart
    JFreeChart jfreechart = new JFreeChart("Sample Combined Plot", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot,
            true);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
            System.out.println(chartmouseevent.getEntity());
        }

        public void chartMouseMoved(ChartMouseEvent chartmouseevent) {
            System.out.println(chartmouseevent.getEntity());
        }

    });
    return chartpanel;
}

From source file:org.drools.planner.benchmark.core.statistic.bestscore.BestScoreProblemStatistic.java

protected void writeGraphStatistic() {
    NumberAxis xAxis = new NumberAxis("Time spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName());
        for (BestScoreSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            Score score = point.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }/* w w  w .j a  v a 2 s . co m*/
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (singleStatistic.getPointList().size() <= 1) {
            // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
            renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " best score statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "BestScoreStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}