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:org.jstockchart.plot.TimeseriesPlot.java

private XYPlot createVolumePlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    VolumeArea volumeArea = timeseriesArea.getVolumeArea();
    LogicNumberAxis logicVolumeAxis = volumeArea.getLogicVolumeAxis();
    Color volumeColor = new Color(86, 126, 160);
    volumeArea.setVolumeColor(volumeColor);
    CFXNumberAxis volumeAxis = new CFXNumberAxis(logicVolumeAxis.getLogicTicks());
    volumeAxis.setAxisLineVisible(false);
    volumeAxis.setCustomTickCount(2);//ww w  .ja  v a2s  .c  o  m
    volumeAxis.setTickLabelPaint(volumeColor);
    volumeAxis.setUpperBound(logicVolumeAxis.getUpperBound());
    volumeAxis.setTickLabelFont(axisFont);
    volumeAxis.setTickMarkStroke(stroke);
    volumeAxis.setLowerBound(logicVolumeAxis.getLowerBound());
    volumeAxis.setAutoRangeIncludesZero(true);
    XYAreaRenderer2 volumeRenderer = new XYAreaRenderer2();
    volumeRenderer.setSeriesPaint(0, volumeArea.getVolumeColor());
    //volumeRenderer.setShadowVisible(false);
    volumeRenderer.setSeriesStroke(0, stroke);
    volumeRenderer.setBaseStroke(stroke);
    XYPlot plot = new XYPlot(new TimeSeriesCollection(dataset.getVolumeTimeSeries()), null, volumeAxis,
            volumeRenderer);
    plot.setBackgroundPaint(volumeArea.getBackgroudColor());
    plot.setOrientation(volumeArea.getOrientation());
    plot.setRangeAxisLocation(volumeArea.getVolumeAxisLocation());
    plot.setRangeMinorGridlinesVisible(false);

    Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
            new float[] { 2.0f, 2.0f }, 1.0f);
    // plot.setBackgroundPaint(Color.RED);
    plot.setRangeGridlineStroke(gridLineStroke);
    plot.setDomainGridlineStroke(gridLineStroke);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setOutlineVisible(true);
    plot.setOutlineStroke(outLineStroke);
    plot.setOutlinePaint(Color.black);
    plot.setRangeZeroBaselineVisible(true);
    return plot;
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createXYZSeriesCollectionChart(
        final XYZSeriesCollectionChartDefinition chartDefinition) {
    JFreeChart chart = null;// w w  w .j  ava2s  .c  o m
    // TODO Make the following accessible from the chartDefinition
    String domainAxisLabel = null;
    String rangeAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel)
            : new NumberAxis(domainAxisLabel);
    domainAxis.setAutoRangeIncludesZero(chartDefinition.isDomainIncludesZero());
    domainAxis.setAutoRangeStickyZero(chartDefinition.isDomainStickyZero());

    NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    rangeAxis.setAutoRangeIncludesZero(chartDefinition.isRangeIncludesZero());
    rangeAxis.setAutoRangeStickyZero(chartDefinition.isRangeStickyZero());

    BubbleRenderer renderer = null;

    // So far only Bubble charts are supported
    switch (chartDefinition.getChartType()) {
    case BUBBLE_CHART_TYPE:
        renderer = new BubbleRenderer();
        break;
    default:
        // should log an error if invalid chart type passed in - at least return null for no renderer
        return null;
    }

    if (tooltips) {
        // creating the label definition

        renderer.setToolTipGenerator(new StandardXYZToolTipGenerator(chartDefinition.getBubbleLabelContent(),
                chartDefinition.getXFormat(), chartDefinition.getYFormat(), chartDefinition.getZFormat()));
    }
    if (urls) {
        renderer.setURLGenerator(new StandardBubbleURLGenerator());
    }

    renderer.setMaxSize(chartDefinition.getMaxBubbleSize());
    renderer.setMaxZ(chartDefinition.getMaxZValue());

    XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);

    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;
}

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

private static XYPlot createSchedulePlot(RunResult result, double granularityInSeconds) {
    TimeTableXYDataset dataset = new TimeTableXYDataset();

    if (granularityInSeconds < 0.001) {
        granularityInSeconds = 0;//from  w w  w .  j  a  va  2s. c o m
    }

    long delta = result.getResponses().get(0).getRequestSubmitTime();
    long firstRequest = 0;
    double windowStart = firstRequest;
    long summedDiffs = 0;
    long numberOfElements = 0;
    Iterator<JMeterResponse> responseIterator = result.getResponses().iterator();
    Iterator<Long> diffIterator = result.getTimestampDiffs().iterator();
    while (responseIterator.hasNext() && diffIterator.hasNext()) {
        AbstractResponse response = responseIterator.next();
        Long diff = diffIterator.next();
        long requestSubmitTime = response.getRequestSubmitTime() - delta;
        if (requestSubmitTime - windowStart > granularityInSeconds * 1000) {
            if (numberOfElements > 0) {
                addDiffToDataset(granularityInSeconds, dataset, windowStart, summedDiffs, numberOfElements);
                numberOfElements = 0;
                summedDiffs = 0;
                firstRequest = requestSubmitTime;
            }
            if (granularityInSeconds > 0) {
                while (requestSubmitTime - windowStart > granularityInSeconds * 1000) {
                    windowStart += granularityInSeconds * 1000;
                }
            } else {
                windowStart = requestSubmitTime;
            }
        }
        numberOfElements++;
        summedDiffs += diff;
    }
    if (numberOfElements > 0) {
        addDiffToDataset(granularityInSeconds, dataset, windowStart, summedDiffs, numberOfElements);
    }
    NumberAxis rangeAxis = new NumberAxis("Request Delay [ms]");
    StackedXYBarRenderer renderer = new StackedXYBarRenderer(0.10);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardXYBarPainter());
    XYPlot plot = new XYPlot(dataset, null, rangeAxis, renderer);
    return plot;
}

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());
        }/*from   w  w  w  . j a v  a2s.co 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.jfree.chart.demo.SymbolicXYPlotDemo.java

/**
 * Displays an horizontally combined XYPlot with X and Y symbolic data.
 * /*w  w  w  .j  ava  2s.c om*/
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           the dataset 1.
 * @param data2
 *           the dataset 2.
 */
private static void displayXYSymbolicCombinedHorizontally(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Pollutant Horizontally Combined";
    final String x1AxisLabel = "Contamination";
    final String x2AxisLabel = "Type";
    final String yAxisLabel = "Pollutant";

    // combine the y symbolic values of the two data sets
    final String[] combinedYSymbolicValues = SampleXYSymbolicDataset
            .combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);

    JFreeChart chart = null;

    // common horizontal and vertical axes
    final SymbolicAxis hsymbolicAxis0 = new SymbolicAxis(x1AxisLabel,
            ((XisSymbolic) data1).getXSymbolicValues());
    final SymbolicAxis hsymbolicAxis1 = new SymbolicAxis(x2AxisLabel,
            ((XisSymbolic) data2).getXSymbolicValues());
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);

    // create main plot...
    final CombinedRangeXYPlot mainPlot = new CombinedRangeXYPlot(symbolicAxis);

    // add subplots...
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot0 = new XYPlot(series0, hsymbolicAxis0, null, renderer);
    final XYPlot subplot1 = new XYPlot(series1, hsymbolicAxis1, null, renderer);
    mainPlot.add(subplot0, 1);
    mainPlot.add(subplot1, 1);

    // make the top level JFreeChart object
    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:com.idealista.solrmeter.view.statistic.CacheHistoryPanel.java

/**
 * Creates the chart of this statistic//from ww w. j a va2 s  . co m
 * @return
 */
private Component createChartPanel() {
    NumberAxis xaxis = new NumberAxis(I18n.get(PREFIX + "time"));
    NumberAxis yaxis = new NumberAxis(I18n.get(PREFIX + "entries"));

    plot = new XYPlot(xyDataset, xaxis, yaxis, new XYLineAndShapeRenderer(true, true));

    chart = new JFreeChart("notitle", null, plot, true);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);
    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setBorder(CHART_BORDER);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);

    return chartPanel;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java

private static JFreeChart createXYLineChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);//from w w w.j ava2s  .c  o  m
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart("XYLine 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:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java

private JFreeChart createVerticalXYBarChart(final Account a, final Account a2) {
    DateFormat df = new SimpleDateFormat("MM/yy");
    TimeSeriesCollection data = createTimeSeriesCollection(a, a2);

    DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    // if (a.getTransactionCount() > 0) {
    Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
    Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
    dateAxis.setRange(start, end);//from  w  ww . j ava2  s. c o m
    // }

    NumberAxis valueAxis = new NumberAxis(
            rb.getString("Column.Balance") + "-" + a.getCurrencyNode().getSymbol());
    StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df,
            NumberFormat.getNumberInstance());
    ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(0.2, false);
    renderer.setBaseToolTipGenerator(tooltipGenerator);

    XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
    String title;
    if (jcb_compare.isSelected()) {
        title = a.getPathName() + " vs " + a2.getPathName();
    } else {
        title = rb.getString("Title.AccountBalance") + " - " + a.getPathName();
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private XYPlot getBarPlot() throws KeyedException {
    // use a number axis on the right side with a special formatter for millions
    NumberAxis axis = new NumberAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setNumberFormatOverride(new NumberFormatForMillions());
    XYPlot plot = new XYPlot(null, null, axis, null);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    return plot;//from   ww  w  . j  a v  a 2  s  . c o  m
}

From source file:org.gumtree.vis.awt.PlotFactory.java

public static JFreeChart createXYBlockChart(IXYZDataset dataset) {
    NumberAxis xAxis = createXAxis(dataset);
    NumberAxis yAxis = createYAxis(dataset);
    NumberAxis scaleAxis = createScaleAxis(dataset);

    float min = (float) dataset.getZMin();
    float max = (float) dataset.getZMax();
    PaintScale scale = generateRainbowScale(min, max, StaticValues.DEFAULT_COLOR_SCALE);
    XYBlockRenderer renderer = createRender(dataset, scale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainPannable(true);/*  w w w  .  j  av  a2s.c  o  m*/
    plot.setRangePannable(true);

    JFreeChart 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, StaticValues.DEFAULT_COLOR_SCALE);
    PaintScaleLegend legend = createScaleLegend(scale, scaleAxis);
    legend.setSubdivisionCount(ColorScale.DIVISION_COUNT);
    //      legend.setStripOutlineVisible(true);
    chart.addSubtitle(legend);
    chart.setBorderVisible(true);
    //      ChartUtilities.applyCurrentTheme(chart);
    chartTheme.apply(chart);
    chart.fireChartChanged();
    return chart;
}