Example usage for org.jfree.chart.renderer.xy XYItemRenderer setSeriesPaint

List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setSeriesPaint

Introduction

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

Prototype

public void setSeriesPaint(int series, Paint paint);

Source Link

Document

Sets the paint used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:net.sf.maltcms.common.charts.api.XYChartBuilder.java

/**
 *
 * @param renderer//from w w w . jav a 2 s .c o m
 * @param datasetSeriesColorMap
 */
protected void setDatasetSeriesColorMap(XYItemRenderer renderer,
        Map<Comparable<?>, Color> datasetSeriesColorMap) {
    if (datasetSeriesColorMap != null) {
        if (datasetSeriesColorMap.keySet().size() != dataset.getSeriesCount()) {
            throw new IllegalArgumentException("Mismatch in series colors and series count!");
        }
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Comparable<?> key = dataset.getSeriesKey(i);
            renderer.setSeriesPaint(i, datasetSeriesColorMap.get(key));
        }
    }
}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart./*ww  w  .ja  v a  2s  . c  o  m*/
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}

From source file:AtomPanel.java

private void initJFreeChart() {
    this.numOfStream = numOfStream;

    datasets = new TimeSeriesCollection();
    trend = new TimeSeriesCollection();
    projpcs = new TimeSeriesCollection();
    spe = new TimeSeriesCollection();

    for (int i = 0; i < MaxNumOfStream; i++) {
        //add streams
        TimeSeries timeseries = new TimeSeries("Stream " + i, Millisecond.class);
        datasets.addSeries(timeseries);/* ww  w.  jav a2s.c  o m*/
        timeseries.setHistoryCount(historyRange);
        //add trend variables
        TimeSeries trendSeries = new TimeSeries("Trend " + i, Millisecond.class);
        trend.addSeries(trendSeries);
        trendSeries.setHistoryCount(historyRange);
        //add proj onto PCs variables
        TimeSeries PC = new TimeSeries("Projpcs " + i, Millisecond.class);
        projpcs.addSeries(PC);
        PC.setHistoryCount(historyRange);
        //add spe streams
        TimeSeries speSeries = new TimeSeries("Spe " + i, Millisecond.class);
        spe.addSeries(speSeries);
        speSeries.setHistoryCount(historyRange);
    }
    combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time"));
    //data stream  plot
    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Streams");
    domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));

    XYItemRenderer renderer = new DefaultXYItemRenderer();
    renderer.setItemLabelsVisible(false);
    renderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(datasets, domain, range, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);

    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    combineddomainxyplot.add(plot);

    //Trend captured by pca
    DateAxis domain0 = new DateAxis("Time");
    NumberAxis range0 = new NumberAxis("PCA Trend");
    domain0.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range0.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain0.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range0.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));

    XYItemRenderer renderer0 = new DefaultXYItemRenderer();
    renderer0.setItemLabelsVisible(false);
    renderer0.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer0.setSeriesPaint(0, Color.blue);
    renderer0.setSeriesPaint(1, Color.red);
    renderer0.setSeriesPaint(2, Color.magenta);
    XYPlot plot0 = new XYPlot(trend, domain0, range0, renderer0);
    plot0.setBackgroundPaint(Color.lightGray);
    plot0.setDomainGridlinePaint(Color.white);
    plot0.setRangeGridlinePaint(Color.white);
    plot0.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    domain0.setAutoRange(true);
    domain0.setLowerMargin(0.0);
    domain0.setUpperMargin(0.0);
    domain0.setTickLabelsVisible(false);

    range0.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    combineddomainxyplot.add(plot0);

    //proj on PCs plot
    DateAxis domain1 = new DateAxis("Time");
    NumberAxis range1 = new NumberAxis("Proj on PCs");
    domain1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain1.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range1.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));

    XYItemRenderer renderer1 = new DefaultXYItemRenderer();
    renderer1.setItemLabelsVisible(false);
    renderer1.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);
    renderer1.setSeriesPaint(1, Color.red);
    renderer1.setSeriesPaint(2, Color.magenta);
    plot1 = new XYPlot(projpcs, domain1, range1, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);
    plot1.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    domain1.setAutoRange(true);
    domain1.setLowerMargin(0.0);
    domain1.setUpperMargin(0.0);
    domain1.setTickLabelsVisible(false);

    range1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    combineddomainxyplot.add(plot1);

    //spe  plot
    DateAxis domain2 = new DateAxis("Time");
    NumberAxis range2 = new NumberAxis("SPE");
    domain2.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range2.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain2.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range2.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));

    XYItemRenderer renderer2 = new DefaultXYItemRenderer();
    renderer2.setItemLabelsVisible(false);
    renderer2.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot2 = new XYPlot(spe, domain2, range2, renderer);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);
    plot2.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    domain2.setAutoRange(true);
    domain2.setLowerMargin(0.0);
    domain2.setUpperMargin(0.0);
    domain2.setTickLabelsVisible(true);

    range2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    combineddomainxyplot.add(plot2);

    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(historyRange); // 60 seconds
    JFreeChart chart;
    if (this.pcaType == AtomUtils.PCAType.pca)
        chart = new JFreeChart("CloudWatch-ATOM with Exact Data", new Font("SansSerif", Font.BOLD, 18),
                combineddomainxyplot, false);
    else if (this.pcaType == AtomUtils.PCAType.pcaTrack)
        chart = new JFreeChart("CloudWatch-ATOM with Fixed Tracking Threshold",
                new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false);
    else
        chart = new JFreeChart("CloudWatch-ATOM with Dynamic Tracking Threshold",
                new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false);
    chart.setBackgroundPaint(Color.white);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    AtomPanel.this.add(chartPanel, BorderLayout.CENTER);
}

From source file:de.tsystems.mms.apm.performancesignature.PerfSigBuildActionResultsDisplay.java

private JFreeChart createTimeSeriesChart(final StaplerRequest req, final XYDataset dataset)
        throws UnsupportedEncodingException {
    String chartDashlet = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamChartDashlet());
    String measure = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamMeasure());
    String unit = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamUnit());
    String color = req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamColor());
    if (StringUtils.isBlank(color))
        color = Messages.PerfSigBuildActionResultsDisplay_DefaultColor();
    else/* w  w  w.j  a  v  a 2s .c  o  m*/
        URLDecoder.decode(req.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamColor()), "UTF-8");

    String[] timeUnits = { "ns", "ms", "s", "min", "h" };
    JFreeChart chart;

    if (ArrayUtils.contains(timeUnits, unit)) {
        chart = ChartFactory.createTimeSeriesChart(PerfSigUtils.generateTitle(measure, chartDashlet), // title
                "time", // domain axis label
                unit, dataset, // data
                false, // include legend
                false, // tooltips
                false // urls
        );
    } else {
        chart = ChartFactory.createXYBarChart(PerfSigUtils.generateTitle(measure, chartDashlet), // title
                "time", // domain axis label
                true, unit, (IntervalXYDataset) dataset, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                false, // tooltips
                false // urls
        );
    }

    XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setForegroundAlpha(0.8f);
    xyPlot.setRangeGridlinesVisible(true);
    xyPlot.setRangeGridlinePaint(Color.black);
    xyPlot.setOutlinePaint(null);

    XYItemRenderer xyitemrenderer = xyPlot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }
    DateAxis dateAxis = (DateAxis) xyPlot.getDomainAxis();
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    xyitemrenderer.setSeriesPaint(0, Color.decode(color));
    xyitemrenderer.setSeriesStroke(0, new BasicStroke(2));

    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:instance.os.OS.java

private JFreeChart getBandwidthChart() {
    JFreeChart chart = ChartFactory.createXYLineChart("Bandwidth per download", "Time (ms)", "Bandwidth (B/s)",
            dataSet, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();/*  ww w.j a  v a2s .c o  m*/
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    return chart;
}

From source file:com.wattzap.view.graphs.SCHRGraph.java

public SCHRGraph(ArrayList<Telemetry> telemetry[]) {
    super();//from   www  .  j  a  v  a 2 s  .  c o m
    this.telemetry = telemetry;

    final NumberAxis domainAxis = new NumberAxis("Time (h:m:s)");

    domainAxis.setVerticalTickLabels(true);
    domainAxis.setTickLabelPaint(Color.black);
    domainAxis.setAutoRange(true);

    domainAxis.setNumberFormatOverride(new NumberFormat() {
        @Override
        public StringBuffer format(double millis, StringBuffer toAppendTo, FieldPosition pos) {
            if (millis >= 3600000) {
                // hours, minutes and seconds
                return new StringBuffer(

                        String.format("%d:%d:%d", TimeUnit.MILLISECONDS.toHours((long) millis),
                                TimeUnit.MILLISECONDS.toMinutes(
                                        (long) millis - TimeUnit.MILLISECONDS.toHours((long) millis) * 3600000),
                                TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES
                                        .toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else if (millis >= 60000) {
                // minutes and seconds
                return new StringBuffer(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) millis),
                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else {
                return new StringBuffer(String.format("%d", TimeUnit.MILLISECONDS.toSeconds((long) millis)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            }
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    // create plot ...
    final XYItemRenderer powerRenderer = new StandardXYItemRenderer() {
        Stroke regularStroke = new BasicStroke(0.7f);
        Color color;

        public void setColor(Color color) {
            this.color = color;
        }

        @Override
        public Stroke getItemStroke(int row, int column) {
            return regularStroke;
        }

        @Override
        public Paint getItemPaint(int row, int column) {
            return orange;
        }
    };
    powerRenderer.setSeriesPaint(0, orange);
    plot = new XYPlot();
    plot.setRenderer(0, powerRenderer);
    plot.setRangeAxis(0, powerAxis);
    plot.setDomainAxis(domainAxis);

    // add a second dataset and renderer...
    final XYItemRenderer cadenceRenderer = new StandardXYItemRenderer() {
        Stroke regularStroke = new BasicStroke(0.7f);
        Color color;

        public void setColor(Color color) {
            this.color = color;
        }

        @Override
        public Stroke getItemStroke(int row, int column) {
            return regularStroke;
        }

        @Override
        public Paint getItemPaint(int row, int column) {
            return cornflower;
        }

        public Shape lookupLegendShape(int series) {
            return new Rectangle(15, 15);
        }
    };

    final ValueAxis cadenceAxis = new NumberAxis(userPrefs.messages.getString("cDrpm"));
    cadenceAxis.setRange(0, 200);

    // arguments of new XYLineAndShapeRenderer are to activate or deactivate
    // the display of points or line. Set first argument to true if you want
    // to draw lines between the points for e.g.
    plot.setRenderer(1, cadenceRenderer);
    plot.setRangeAxis(1, cadenceAxis);
    plot.mapDatasetToRangeAxis(1, 1);
    cadenceRenderer.setSeriesPaint(0, cornflower);

    // add a third dataset and renderer...
    final XYItemRenderer hrRenderer = new StandardXYItemRenderer() {
        Stroke regularStroke = new BasicStroke(0.7f);
        Color color;

        public void setColor(Color color) {
            this.color = color;
        }

        @Override
        public Stroke getItemStroke(int row, int column) {
            return regularStroke;
        }

        @Override
        public Paint getItemPaint(int row, int column) {
            return straw;
        }

    };

    // arguments of new XYLineAndShapeRenderer are to activate or deactivate
    // the display of points or line. Set first argument to true if you want
    // to draw lines between the points for e.g.
    final ValueAxis heartRateAxis = new NumberAxis(userPrefs.messages.getString("hrBpm"));
    heartRateAxis.setRange(0, 200);

    plot.setRenderer(2, hrRenderer);
    hrRenderer.setSeriesPaint(0, straw);

    plot.setRangeAxis(2, heartRateAxis);
    plot.mapDatasetToRangeAxis(2, 2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.getLegend().setBackgroundPaint(Color.gray);

    chartPanel = new ChartPanel(chart);

    // TODO: maybe remember sizes set by user?
    this.setPreferredSize(new Dimension(1200, 500));
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setBackground(Color.gray);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);

    SmoothingPanel smoothingPanel = new SmoothingPanel(this);
    add(smoothingPanel, BorderLayout.SOUTH);

    //infoPanel = new InfoPanel();
    //add(infoPanel, BorderLayout.NORTH);
    setVisible(true);
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a Chart.//w  w w  . ja  v  a 2  s. c  om
 *
 * @param title        the title of the chart.
 * @param data         the data to use in the chart.
 * @param xAxis        the variables to use on the xAxis.
 * @param yAxis        the variables to use on the yAxis.
 * @param orientation  the orientation
 * @param itemRenderer the type of renderer to use.
 * @return the generated chart.
 */
private JFreeChart createChart(String title, XYDataset data, ValueAxis xAxis, ValueAxis yAxis,
        PlotOrientation orientation, XYItemRenderer itemRenderer, GraphDefinition def) {
    int seriesCount = data.getSeriesCount();
    for (int i = 0; i < seriesCount; i++) {
        itemRenderer.setSeriesPaint(i, def.getInlineColor(i));
        itemRenderer.setSeriesOutlinePaint(i, def.getOutlineColor(i));
    }

    XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
    plot.setOrientation(orientation);
    plot.setRenderer(itemRenderer);

    return createChart(title, plot);
}

From source file:sim.util.media.chart.TimeSeriesAttributes.java

public void rebuildGraphicsDefinitions() {
    float[] newDashPattern = new float[dashPatterns[dashPattern].length];
    for (int x = 0; x < newDashPattern.length; x++)
        if (stretch * thickness > 0)
            newDashPattern[x] = dashPatterns[dashPattern][x] * stretch * thickness; // include thickness so we dont' get overlaps -- will this confuse users?

    XYItemRenderer renderer = (XYItemRenderer) (((XYPlot) getPlot()).getRenderer());

    // we do two different BasicStroke options here because recent versions of Java (for example, 1.6.0_35_b10-428-11M3811 on Retina Displays)
    // break when defining solid strokes as { X, 0.0 } even though that's perfecty cromulent.  So instead we hack it so that the "solid" stroke
    // is done using a different constructor.

    renderer.setSeriesStroke(getSeriesIndex(), ((dashPattern == 0) ? // solid
            new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0)
            : new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, newDashPattern, 0)));

    renderer.setSeriesPaint(getSeriesIndex(), strokeColor);
    repaint();/*from w ww. j  av  a2 s. co  m*/
}

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.ja  va 2 s.  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);
}