Example usage for org.jfree.chart.renderer.xy StandardXYItemRenderer SHAPES

List of usage examples for org.jfree.chart.renderer.xy StandardXYItemRenderer SHAPES

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy StandardXYItemRenderer SHAPES.

Prototype

int SHAPES

To view the source code for org.jfree.chart.renderer.xy StandardXYItemRenderer SHAPES.

Click Source Link

Document

Constant for the type of rendering (shapes only).

Usage

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

/**
 * Starting point for the demo.//  www  . ja v  a  2s. c  o m
 *
 * @param args  ignored.
 *
 * @throws ParseException if there is a problem parsing dates.
 */
public static void main(final String[] args) throws ParseException {

    //  Create a sample dataset
    final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    final XYSeries dataSeries = new XYSeries("Curve data");
    final ArrayList toolTips = new ArrayList();
    dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22);
    toolTips.add("1D - 5.22");
    dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18);
    toolTips.add("2D - 5.18");
    dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23);
    toolTips.add("3D - 5.23");
    dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15);
    toolTips.add("4D - 5.15");
    dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22);
    toolTips.add("5D - 5.22");
    dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25);
    toolTips.add("6D - 5.25");
    dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31);
    toolTips.add("7D - 5.31");
    dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36);
    toolTips.add("8D - 5.36");
    final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
    final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator();
    ttg.addToolTipSeries(toolTips);

    //  Create the chart
    final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp");
    final ValueAxis timeAxis = new DateAxis("");
    final NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null);
    final StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
            StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg);
    sxyir.setShapesFilled(true);
    plot.setRenderer(sxyir);
    final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("xychart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("xychart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"xychart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return;
}

From source file:de.laures.cewolf.taglib.PlotTypes.java

/**
 * Create a renderer for the given type index.
 * We create a new renderer instance for each chart, because they may want to customize
 * it in a post-processor./*from w  w w  .  j av  a2s  . c  om*/
 * 
 * @param idx The index of the type
 * @return A new renderer instance
 */
public static AbstractRenderer getRenderer(int idx) {
    switch (idx) {
    case 0:
        return new XYAreaRenderer();
    case 1:
        return new StandardXYItemRenderer();
    case 2:
        return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
    case 3:
        return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    case 4:
        return new XYBarRenderer();
    case 5:
        return new XYStepRenderer();
    case 6:
        return new CandlestickRenderer();
    case 7:
        return new HighLowRenderer();
    //case 8: return new SignalRenderer();
    case 9:
        return new BarRenderer();
    case 10:
        return new AreaRenderer();
    case 11:
        return new LineAndShapeRenderer(true, false);
    case 12:
        return new LineAndShapeRenderer(true, true);
    default:
        throw new RuntimeException("Invalid renderer index:" + idx);
    }
}

From source file:peakmlviewer.dialog.PCADialog.java

public PCADialog(MainWnd mainwnd, Shell parent, String title) {
    super(parent, SWT.NONE);

    // save the parent pointer
    this.title = title;
    this.parent = parent;

    this.mainwnd = mainwnd;

    // create the window and set its properties
    shell = new Shell(parent, SWT.EMBEDDED | SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    shell.setSize(500, 300);/*from ww w .j  a v  a2s . c  om*/
    shell.setText(title);

    // create the jfreechart
    plot = new XYPlot(collection, new NumberAxis("principal component 1"),
            new NumberAxis("principal component 2"), new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.getRenderer().setBaseItemLabelsVisible(true);
    plot.getRenderer().setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        public String generateLabel(XYDataset dataset, int series, int item) {
            return labels[item];
        }
    });

    chart = new JFreeChart("Principle Component Analysis", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.WHITE);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding awt-controls in an SWT-Composit.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(shell);

    // create a new ChartPanel, without the popup-menu (5x false)
    frame.add(new ChartPanel(chart, false, false, false, false, false));
    // --------------------------------------------------------------------------------
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void visit(PointStyler styler) {
    styler.resetIterators();/* w w w .j ava 2 s  . c om*/
    if (styler.getNumPoints() == 0)
        return;

    // create dataset and renderer            
    XYDataset dataset = new ChartXYDataset(currentItem.getName(), styler);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);

    // point color and size
    PointGraphic point = styler.getPoint(0);
    renderer.setPaint(new Color(point.r, point.g, point.b, point.a));

    // point shape
    Shape shape = null;
    switch (point.shape) {
    case SQUARE:
        shape = new Rectangle2D.Float(-point.size / 2, -point.size / 2, point.size, point.size);
        break;

    case CIRCLE:
        shape = new Ellipse2D.Float(-point.size / 2, -point.size / 2, point.size, point.size);
        break;

    case TRIANGLE:
        int[] xPoints = new int[] { -(int) point.size / 2, 0, (int) point.size / 2 };
        int[] yPoints = new int[] { (int) point.size / 2, -(int) point.size / 2, (int) point.size / 2 };
        shape = new Polygon(xPoints, yPoints, 3);
        break;
    }
    renderer.setShape(shape);

    // add new dataset and corresponding renderer and range axis
    addDataSet(dataset, renderer);
}

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);
            }//from   w w  w  .j av  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);
    }
}

From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createPeriodCostPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    XYSeries series = new XYSeries("Power price");
    for (PeriodPowerPrice periodPowerPrice : solution.getPeriodPowerPriceList()) {
        series.add((double) periodPowerPrice.getPowerPriceMicros() / 1000000.0, periodPowerPrice.getPeriod());
    }/*from  www .  java  2  s . c o m*/
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    seriesCollection.addSeries(series);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    renderer.setSeriesPaint(0, TangoColorFactory.ORANGE_1);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(2.0F));
    NumberAxis domainAxis = new NumberAxis("Power price");
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

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

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    NumberAxis xAxis = new NumberAxis("Time millis 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 (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {//from   w w  w.j a v  a 2 s  . c o  m
        String configName = listenerEntry.getKey();
        XYSeries series = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (statisticPointList.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(baseName + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "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);
    }
    return "  <img src=\"" + graphStatisticFile.getName() + "\"/>\n";
}

From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createAvailableCapacityPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    Map<MachineCapacity, List<Integer>> availableMap = new LinkedHashMap<MachineCapacity, List<Integer>>(
            solution.getMachineCapacityList().size());
    for (MachineCapacity machineCapacity : solution.getMachineCapacityList()) {
        List<Integer> machineAvailableList = new ArrayList<Integer>(solution.getGlobalPeriodRangeTo());
        for (int period = 0; period < solution.getGlobalPeriodRangeTo(); period++) {
            machineAvailableList.add(machineCapacity.getCapacity());
        }/*w  ww.  j a v a2  s.c  o m*/
        availableMap.put(machineCapacity, machineAvailableList);
    }
    for (TaskAssignment taskAssignment : solution.getTaskAssignmentList()) {
        Machine machine = taskAssignment.getMachine();
        Integer startPeriod = taskAssignment.getStartPeriod();
        if (machine != null && startPeriod != null) {
            Task task = taskAssignment.getTask();
            List<TaskRequirement> taskRequirementList = task.getTaskRequirementList();
            for (int i = 0; i < taskRequirementList.size(); i++) {
                TaskRequirement taskRequirement = taskRequirementList.get(i);
                MachineCapacity machineCapacity = machine.getMachineCapacityList().get(i);
                List<Integer> machineAvailableList = availableMap.get(machineCapacity);
                for (int j = 0; j < task.getDuration(); j++) {
                    int period = j + taskAssignment.getStartPeriod();
                    int available = machineAvailableList.get(period);
                    machineAvailableList.set(period, available - taskRequirement.getResourceUsage());
                }
            }
        }
    }
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    int seriesIndex = 0;
    for (Machine machine : solution.getMachineList()) {
        XYSeries machineSeries = new XYSeries(machine.getLabel());
        for (MachineCapacity machineCapacity : machine.getMachineCapacityList()) {
            List<Integer> machineAvailableList = availableMap.get(machineCapacity);
            for (int period = 0; period < solution.getGlobalPeriodRangeTo(); period++) {
                int available = machineAvailableList.get(period);
                machineSeries.add(available, period);
            }
        }
        seriesCollection.addSeries(machineSeries);
        renderer.setSeriesPaint(seriesIndex, tangoColorFactory.pickColor(machine));
        renderer.setSeriesShape(seriesIndex, ShapeUtilities.createDiamond(1.5F));
        renderer.setSeriesVisibleInLegend(seriesIndex, false);
        seriesIndex++;
    }
    NumberAxis domainAxis = new NumberAxis("Capacity");
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void addIsotopeCurves(TreeMap<Peak, Collection<Annotation>> annotations) {

    if (theDocument.size() == 0)
        return;//from   w  w  w. ja v  a2  s .  c o  m

    // remove old curves
    removeIsotopeCurves();

    // add curves
    if (annotations != null) {

        // set renderer
        if (show_all_isotopes) {
            thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));
            thePlot.getRenderer(1).setShape(new Ellipse2D.Double(0, 0, 7, 7));
        } else
            thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.LINES));

        MSUtils.IsotopeList isotope_list = new MSUtils.IsotopeList(show_all_isotopes);
        for (Map.Entry<Peak, Collection<Annotation>> pa : annotations.entrySet()) {
            Peak p = pa.getKey();

            // get compositions
            HashSet<Molecule> compositions = new HashSet<Molecule>();
            for (Annotation a : pa.getValue()) {
                try {
                    compositions.add(a.getFragmentEntry().fragment.computeIon());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            // collect curves for this peak
            HashMap<String, double[][]> all_curves = new HashMap<String, double[][]>();
            for (Molecule m : compositions) {
                try {
                    double[][] data = MSUtils.getIsotopesCurve(1, m, show_all_isotopes);
                    // overlay the distribution with the existing list of isotopes
                    isotope_list.adjust(data, p.getMZ(), p.getIntensity());

                    all_curves.put(m.toString(), data);
                } catch (Exception e) {
                    LogUtils.report(e);
                }
            }

            // add average curve for this peak
            if (all_curves.size() > 1) {
                double[][] data = MSUtils.average(all_curves.values(), show_all_isotopes);
                // add the average to the chart
                String name = "average-" + p.getMZ();
                theIsotopesDataset.addSeries(name, data);
                thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.magenta);
                thePlot.getRenderer(1).setSeriesStroke(theIsotopesDataset.indexOf(name), new BasicStroke(2));

                // add the average to the isotope list
                isotope_list.add(data, false);
            } else if (all_curves.size() == 1) {
                // add the only curve to the isotope list
                isotope_list.add(all_curves.values().iterator().next(), false);
            }

            // add the other curves
            for (Map.Entry<String, double[][]> e : all_curves.entrySet()) {
                String name = e.getKey() + "-" + p.getMZ();
                theIsotopesDataset.addSeries(name, e.getValue());
                thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.blue);
            }
        }
    }
    updateIntensityAxis();
}

From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

private JFreeChart createChart(XYDataset data) {
    ValueAxis timeAxis = new DateAxis("Date/Time");
    timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
    timeAxis.setUpperMargin(0.02);/*from  w w  w .j  a  v a2 s . c om*/
    NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);
    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null, null));
    JFreeChart chart = new JFreeChart("Cookie values over time", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    return chart;
}