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:edu.umn.ecology.populus.plot.BasicPlotCanvas.java

private void jbInit() throws Exception {
    /*/*from w  ww  .j ava  2  s. c o m*/
    if( info != null ) {
       mainCaption = new HTMLLabel( info.getMainCaption() );
       xCaption = new HTMLLabel( info.getXCaptions()[0] );
       yCaption = new HTMLLabel( info.getYCaptions()[0] );
       yCaption.setDirection( HTMLLabel.DOWN_TO_UP );
    } else {
       mainCaption = new HTMLLabel( "Main Caption" );
       xCaption = new HTMLLabel( "X Caption" );
       yCaption = new HTMLLabel( "Y Caption" );
    }
     */
    //*
    if (info != null) {
        mainCaption = new HTMLMultiLabel(info.getMainCaption());
        xCaption = new HTMLMultiLabel(info.getXCaptions());
        yCaption = new HTMLMultiLabel(info.getYCaptions());
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    } else {
        mainCaption = new HTMLMultiLabel("Main Caption");
        xCaption = new HTMLMultiLabel("X Caption");
        yCaption = new HTMLMultiLabel("Y Caption");
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    }
    setLayout(borderLayout1);
    if (PopPreferencesStorage.isUseJFreeClass()) {
        NumberAxis yAxis = new NumberAxis(null);
        NumberAxis xAxis = new NumberAxis(null);
        xAxis.setAutoRangeIncludesZero(false);

        AbstractXYItemRenderer renderer = null;
        if (info.isBarChart) {
            renderer = new XYBarRenderer();
        } else {
            renderer = new XYLineAndShapeRenderer(true, false);
        }

        XYPlot plot = new XYPlot(null, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        JFreeChart jfchart = new JFreeChart(null, null, plot, false);
        jfchartpanel = new ChartPanel(jfchart);
        plot.setBackgroundPaint(ColorScheme.bG);

        info.styleJFree(jfchart);
        add(jfchartpanel, MacroLayout.CENTER);
    } else {
        chart = new JCChart(JCChart.PLOT);
        info.styleJC(chart);
        chart.setBackground(ColorScheme.bG);
        chart.setAllowUserChanges(true);
        chart.setTrigger(0, new EventTrigger(InputEvent.SHIFT_MASK, EventTrigger.CUSTOMIZE));
        chart.setTrigger(1, new EventTrigger(InputEvent.BUTTON1_MASK, EventTrigger.ZOOM));
        chart.setResetKey('r');
        chart.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent e) {
                if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
                    info.setAxis(chart);
                    chart.reset();
                }
            }
        });
        chart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        chart.setWarningDialog(false);
        add(chart, MacroLayout.CENTER);
    }
    setBGColor();
    add(mainCaption, MacroLayout.NORTH);
    add(xCaption, MacroLayout.SOUTH);
    add(yCaption, MacroLayout.WEST);
}

From source file:org.jls.toolbox.math.chart.XYBlockChart.java

/**
 * Permet de crer le graphique  partir des paramtres spcifis.
 *//*from  w  w w .  j a  v a 2  s. c  o  m*/
private void createChart() {
    // Cration des axes
    NumberAxis xAxis = new NumberAxis(this.xTitle);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLabelFont(new Font("Dialog", Font.BOLD, 14));
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    NumberAxis yAxis = new NumberAxis(this.yTitle);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLabelFont(new Font("Dialog", Font.BOLD, 14));
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);

    this.renderer = new XYBlockRenderer();
    PaintScale scale = new GrayPaintScale(0, 10);
    this.renderer.setPaintScale(scale);

    // Cration de la courbe
    this.plot = new XYPlot(this.dataset, xAxis, yAxis, this.renderer);

    // Cration du graphique
    this.chart = new JFreeChart(this.title, this.plot);
    this.chart.removeLegend();

    createPaintScaleLegend(scale);
    setColorGradient(Color.yellow, Color.red, 0, 1);
}

From source file:edu.cudenver.bios.chartsvc.resource.ScatterPlotResource.java

/**
 * Create a JFreeChart object from the chart specification.  JFreechart provides 
 * functionality to render 2D scatter plots as jpeg images
 * //w  ww  .  j av  a 2s .co  m
 * @param chart chart specification object
 * @return JFreeChart object
 * @throws ResourceException
 */
private JFreeChart buildScatterPlot(Chart chart) throws ResourceException {
    ArrayList<LineStyle> lineStyleList = chart.getLineStyleList();

    float dashedLength = 1.0f;
    float spaceLength = 1.0f;
    float thickness = 1.0f;

    // the first series is treated as the x values
    if (chart.getSeries() == null || chart.getSeries().size() <= 0)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified");

    // create the jfree chart series
    XYSeriesCollection chartData = new XYSeriesCollection();
    // use a spline renderer to make the connecting lines smooth
    XYSplineRenderer rend = new XYSplineRenderer();

    int seriesIdx = 0;

    for (Series series : chart.getSeries()) {
        XYSeries xySeries = new XYSeries(series.getLabel());

        List<Double> xList = series.getXCoordinates();
        List<Double> yList = series.getYCoordinates();
        if (xList != null && yList != null && xList.size() == yList.size()) {
            for (int i = 0; i < xList.size(); i++) {
                xySeries.add(xList.get(i), yList.get(i));
            }
        }

        if (seriesIdx >= 0 && seriesIdx < lineStyleList.size()) {
            LineStyle lineStyle = lineStyleList.get(seriesIdx);
            dashedLength = (float) lineStyle.getDashLength();
            spaceLength = (float) lineStyle.getSpaceLength();
            thickness = (float) lineStyle.getWidth();
        } else {
            dashedLength = 1.0f;
            spaceLength = 1.0f;
            thickness = 1.0f;
        }

        // set the line style
        rend.setSeriesPaint(seriesIdx, Color.BLACK);

        if (seriesIdx >= 0) {
            /*rend.setSeriesStroke(seriesIdx, 
                  new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {(float) seriesIdx, (float) 2*seriesIdx}, 0.0f));*/
            rend.setSeriesStroke(seriesIdx, new BasicStroke(thickness, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND, 1.0f, new float[] { dashedLength, spaceLength }, 0.0f));
        }
        // add the series to the data set
        chartData.addSeries(xySeries);
        seriesIdx++;
    }

    // turn off shapes displayed at each data point to make a smooth curve
    rend.setBaseShapesVisible(false);

    // Create the line chart
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    if (chart.getXAxis() != null) {
        Axis xAxisSpec = chart.getXAxis();
        xAxis.setLabel(xAxisSpec.getLabel());
        if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) {
            xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax());
        }
    }
    NumberAxis yAxis = new NumberAxis();
    if (chart.getYAxis() != null) {
        Axis yAxisSpec = chart.getYAxis();
        yAxis.setLabel(chart.getYAxis().getLabel());
        if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) {
            xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax());
        }
    }
    XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    JFreeChart renderedChart = new JFreeChart(chart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    renderedChart.setBackgroundPaint(Color.WHITE);
    if (chart.hasLegend()) {
        LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
        legend.setFrame(BlockBorder.NONE);
        legend.setPosition(RectangleEdge.BOTTOM);
        renderedChart.addLegend(legend);
    }

    return renderedChart;
}

From source file:it.cnr.istc.iloc.gui.StateVariableVisualizer.java

@Override
public Collection<XYPlot> getPlots(Type type) {
    Collection<IItem> instances = type.getInstances();
    Collection<XYPlot> plots = new ArrayList<>(instances.size());
    Map<IItem, Collection<Atom>> sv_atoms = new IdentityHashMap<>(instances.size());
    for (IItem i : type.getInstances()) {
        sv_atoms.put(i, new ArrayList<>());
    }/*  w w w .  j  ava2  s.c o m*/
    for (Atom atom : ((StateVariable) type).getDefinedPredicates().stream()
            .flatMap(p -> p.getInstances().stream()).map(a -> (Atom) a)
            .filter(a -> a.state.evaluate().isSingleton() && a.state.evaluate().contains(AtomState.Active))
            .collect(Collectors.toList())) {
        for (IItem i : ((IEnumItem) atom.get(SCOPE)).getEnumVar().evaluate().getAllowedValues()) {
            if (sv_atoms.containsKey(i)) {
                sv_atoms.get(i).add(atom);
            }
        }
    }

    for (IItem sv : instances) {
        Collection<Atom> atoms = sv_atoms.get(sv);
        // For each pulse the atoms starting at that pulse
        Map<Double, Collection<Atom>> starting_atoms = new HashMap<>(atoms.size());
        // For each pulse the atoms ending at that pulse
        Map<Double, Collection<Atom>> ending_atoms = new HashMap<>(atoms.size());

        // The pulses of the timeline
        Set<Double> c_pulses = new HashSet<>(atoms.size() * 2);

        for (Atom atom : atoms) {
            double start = sv.getCore().evaluate(((IArithItem) atom.get("start")).getArithVar());
            double end = sv.getCore().evaluate(((IArithItem) atom.get("end")).getArithVar());

            if (!starting_atoms.containsKey(start)) {
                starting_atoms.put(start, new ArrayList<>());
            }
            starting_atoms.get(start).add(atom);

            if (!ending_atoms.containsKey(end)) {
                ending_atoms.put(end, new ArrayList<>());
            }
            ending_atoms.get(end).add(atom);

            c_pulses.add(start);
            c_pulses.add(end);
        }

        // we sort current pulses..
        Double[] c_pulses_array = c_pulses.toArray(new Double[c_pulses.size()]);
        Arrays.sort(c_pulses_array);

        XYIntervalSeriesCollection collection = new XYIntervalSeriesCollection();

        ValueXYIntervalSeries undefined = new ValueXYIntervalSeries("Undefined");
        ValueXYIntervalSeries sv_values = new ValueXYIntervalSeries("Values");
        ValueXYIntervalSeries conflicts = new ValueXYIntervalSeries("Conflicts");

        List<Atom> overlapping_atoms = new ArrayList<>();
        for (int i = 0; i < c_pulses_array.length - 1; i++) {
            if (starting_atoms.containsKey(c_pulses_array[i])) {
                overlapping_atoms.addAll(starting_atoms.get(c_pulses_array[i]));
            }
            if (ending_atoms.containsKey(c_pulses_array[i])) {
                overlapping_atoms.removeAll(ending_atoms.get(c_pulses_array[i]));
            }
            switch (overlapping_atoms.size()) {
            case 0:
                undefined.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1,
                        new Atom[0]);
                break;
            case 1:
                sv_values.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1,
                        overlapping_atoms.toArray(new Atom[overlapping_atoms.size()]));
                break;
            default:
                conflicts.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1,
                        overlapping_atoms.toArray(new Atom[overlapping_atoms.size()]));
                break;
            }
        }

        collection.addSeries(undefined);
        collection.addSeries(sv_values);
        collection.addSeries(conflicts);

        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setSeriesPaint(0, Color.lightGray);
        renderer.setSeriesPaint(1, new Color(100, 250, 100));
        renderer.setSeriesPaint(2, Color.pink);
        renderer.setBarPainter(new ReverseGradientXYBarPainter());
        renderer.setDrawBarOutline(true);
        renderer.setShadowXOffset(2);
        renderer.setShadowYOffset(2);
        renderer.setUseYInterval(true);

        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelPaint(Color.black);
        Font font = new Font("SansSerif", Font.PLAIN, 9);
        renderer.setBaseItemLabelFont(font);
        XYItemLabelGenerator generator = (XYDataset dataset, int series,
                int item) -> toString(((ValueXYIntervalDataItem) ((XYIntervalSeriesCollection) dataset)
                        .getSeries(series).getDataItem(item)).atoms);
        ItemLabelPosition itLabPos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
        renderer.setBasePositiveItemLabelPosition(itLabPos);
        for (int i = 0; i < collection.getSeriesCount(); i++) {
            renderer.setSeriesItemLabelGenerator(i, generator);
            renderer.setSeriesItemLabelsVisible(i, true);
            renderer.setSeriesItemLabelPaint(i, Color.black);
            renderer.setSeriesItemLabelFont(i, font);
            renderer.setSeriesPositiveItemLabelPosition(i, itLabPos);
            renderer.setSeriesToolTipGenerator(i,
                    (XYDataset dataset, int series, int item) -> toString(
                            ((ValueXYIntervalDataItem) ((XYIntervalSeriesCollection) dataset).getSeries(series)
                                    .getDataItem(item)).atoms));
        }

        XYPlot plot = new XYPlot(collection, null, new NumberAxis(""), renderer);
        plot.getRangeAxis().setVisible(false);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        plots.add(plot);
    }

    return plots;
}

From source file:tools.descartes.bungee.chart.ChartGenerator.java

public static XYPlot createResponseTimePlot(RunResult result, String name, double granularityInSeconds) {
    TimeTableXYDataset dataset = new TimeTableXYDataset();

    if (granularityInSeconds < 0.001) {
        granularityInSeconds = 0;/*from   ww  w  . java 2  s  .c  o m*/
    }

    long delta = result.getResponses().get(0).getRequestSubmitTime();
    long firstRequest = 0;
    double windowStart = firstRequest;
    long summedResponseTimes = 0;
    long summedWorkTimes = 0;
    long numberOfElements = 0;

    for (JMeterResponse response : result.getResponses()) {
        long requestSubmitTime = response.getRequestSubmitTime() - delta;
        if (requestSubmitTime - windowStart > granularityInSeconds * 1000) {
            if (numberOfElements > 0) {
                addResponseTimeToDataset(dataset, granularityInSeconds, (long) windowStart, summedResponseTimes,
                        summedWorkTimes, numberOfElements, name);
                numberOfElements = 0;
                summedResponseTimes = 0;
                summedWorkTimes = 0;
                firstRequest = requestSubmitTime;
            }
            if (granularityInSeconds > 0) {
                while (requestSubmitTime - windowStart > granularityInSeconds * 1000) {
                    windowStart += granularityInSeconds * 1000;
                }
            } else {
                windowStart = requestSubmitTime;
            }
        }
        numberOfElements++;
        summedResponseTimes += response.getResponseTime();
        summedWorkTimes += response.getRequestServiceTime();
    }
    if (numberOfElements > 0) {
        addResponseTimeToDataset(dataset, granularityInSeconds, (long) windowStart, summedResponseTimes,
                summedWorkTimes, numberOfElements, name);
    }

    NumberAxis rangeAxis = new NumberAxis("Resp.Time [ms]");
    rangeAxis.setRange(0, 1100);
    StackedXYBarRenderer renderer = new StackedXYBarRenderer(0.10);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setSeriesPaint(0, Color.GRAY);
    renderer.setSeriesPaint(1, colorForConfig(name));
    XYPlot plot = new XYPlot(dataset, null, rangeAxis, renderer);
    return plot;
}

From source file:pisco.batch.visu.BatchingChartFactory.java

public static XYPlot createBatchPlot(Batch[] batches, int capacity) {
    final XYBarRenderer renderer = new StackedXYBarRendererPaletteByItems(makePalette(batches.length));
    renderer.setShadowVisible(false);/*www .ja v  a  2s  . com*/
    renderer.setShadowXOffset(0);
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlineStroke(new BasicStroke(2));
    final BatchLabelToolTipGenerator lpg = new BatchLabelToolTipGenerator();
    renderer.setBaseItemLabelGenerator(lpg);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseToolTipGenerator(lpg);
    XYPlot plot = new XYPlot(new BatchProcessingDataset(batches), null, createIntegerAxis("Load"), renderer);

    if (capacity > 0) {
        Marker capaMarker = createCapacityMarker(capacity, "Capacity", B_RED);
        plot.addRangeMarker(0, capaMarker, Layer.FOREGROUND);
    }
    return plot;
}

From source file:org.drools.planner.benchmark.statistic.memoryuse.MemoryUseStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (Map.Entry<String, MemoryUseStatisticListener> listenerEntry : statisticListenerMap.entrySet()) {
        String configName = listenerEntry.getKey();
        XYSeries usedSeries = new XYSeries(configName + " used");
        XYSeries maxSeries = new XYSeries(configName + " max");
        List<MemoryUseStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (MemoryUseStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            MemoryUseMeasurement memoryUseMeasurement = statisticPoint.getMemoryUseMeasurement();
            usedSeries.add(timeMillisSpend, memoryUseMeasurement.getUsedMemory());
            maxSeries.add(timeMillisSpend, memoryUseMeasurement.getMaxMemory());
        }/*  w ww .  ja v a 2s .  co m*/
        seriesCollection.addSeries(usedSeries);
        seriesCollection.addSeries(maxSeries);
    }
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Memory");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYAreaRenderer2();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "MemoryUseStatistic.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.rdv.viz.chart.ChartViz.java

/**
 * Create the chart and setup it's UI.//from  w w  w  .jav  a  2s  .  c  om
 */
private void initChart() {
    XYToolTipGenerator toolTipGenerator;

    if (xyMode) {
        dataCollection = new XYTimeSeriesCollection();

        NumberAxis domainAxis = new NumberAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        domainAxis.addChangeListener(new AxisChangeListener() {
            public void axisChanged(AxisChangeEvent ace) {
                boundsChanged();
            }
        });
        this.domainAxis = domainAxis;

        toolTipGenerator = new StandardXYToolTipGenerator("{0}: {1} , {2}", new DecimalFormat(),
                new DecimalFormat());
    } else {
        dataCollection = new TimeSeriesCollection();

        domainAxis = new FixedAutoAdjustRangeDateAxis();
        domainAxis.setLabel("Time");
        domainAxis.setAutoRange(false);

        toolTipGenerator = new StandardXYToolTipGenerator("{0}: {1} , {2}",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), new DecimalFormat());
    }

    rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.addChangeListener(new AxisChangeListener() {
        public void axisChanged(AxisChangeEvent ace) {
            boundsChanged();
        }
    });

    FastXYItemRenderer renderer = new FastXYItemRenderer(StandardXYItemRenderer.LINES, toolTipGenerator);
    renderer.setBaseCreateEntities(false);
    renderer.setBaseStroke(new BasicStroke(0.5f));
    if (xyMode) {
        renderer.setCursorVisible(true);
    }

    xyPlot = new XYPlot(dataCollection, domainAxis, rangeAxis, renderer);

    chart = new JFreeChart(xyPlot);
    chart.setAntiAlias(false);

    seriesLegend = chart.getLegend();
    chart.removeLegend();

    chartPanel = new ChartPanel(chart, true);
    chartPanel.setInitialDelay(0);

    // get the chart panel standard popup menu
    JPopupMenu popupMenu = chartPanel.getPopupMenu();

    // create a popup menu item to copy an image to the clipboard
    final JMenuItem copyChartMenuItem = new JMenuItem("Copy");
    copyChartMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyChart();
        }
    });
    popupMenu.insert(copyChartMenuItem, 2);

    popupMenu.insert(new JPopupMenu.Separator(), 3);

    popupMenu.add(new JPopupMenu.Separator());

    showLegendMenuItem = new JCheckBoxMenuItem("Show Legend", true);
    showLegendMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setShowLegend(showLegendMenuItem.isSelected());
        }
    });
    popupMenu.add(showLegendMenuItem);

    if (xyMode) {
        popupMenu.add(new JPopupMenu.Separator());

        JMenuItem addLocalSeriesMenuItem = new JMenuItem("Add local series...");
        addLocalSeriesMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                addLocalSeries();
            }
        });

        popupMenu.add(addLocalSeriesMenuItem);
    }

    chartPanelPanel = new JPanel();
    chartPanelPanel.setLayout(new BorderLayout());
    chartPanelPanel.add(chartPanel, BorderLayout.CENTER);
}

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

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {//from   www  .j  a v a 2s  . com
        String configName = listenerEntry.getKey();
        XYSeries configSeries = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue()
                .getBestScoreStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                configSeries.add(timeMillisSpend, scoreGraphValue);
            }
        }
        seriesCollection.addSeries(configSeries);
    }
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYStepRenderer();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    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 + "Statistic.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.benchmark.impl.statistic.single.pickedmovetypestepscore.PickedMoveTypeStepScoreDiffSingleStatistic.java

private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Step score diff level " + scoreLevelIndex);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(true);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;/*  w  w  w .j  a va 2 s  . c o  m*/
}