Example usage for org.jfree.chart JFreeChart setPadding

List of usage examples for org.jfree.chart JFreeChart setPadding

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart setPadding.

Prototype

public void setPadding(RectangleInsets padding) 

Source Link

Document

Sets the padding between the chart border and the chart drawing area, and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private byte[] generateTimeSeriesChart(String siteId, IntervalXYDataset dataset, int width, int height,
        boolean renderBar, float transparency, boolean itemLabelsVisible, boolean smallFontInDomainAxis,
        String timePeriod, Date firstDate, Date lastDate) {
    JFreeChart chart = null;
    if (!renderBar) {
        chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, true, false, false);
    } else {/*from ww w.ja v  a  2  s. c  o  m*/
        chart = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL, true,
                false, false);
    }
    XYPlot plot = (XYPlot) chart.getPlot();

    // set transparency
    plot.setForegroundAlpha(transparency);

    // set background
    chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set antialias
    chart.setAntiAlias(true);

    // set domain axis font size
    if (smallFontInDomainAxis && !canUseNormalFontSize(width)) {
        plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    }

    // configure date display (localized) in domain axis
    Locale locale = msgs.getLocale();
    PeriodAxis periodaxis = new PeriodAxis(null);
    Class timePeriodClass = null;
    if (dataset instanceof TimeSeriesCollection) {
        TimeSeriesCollection tsc = (TimeSeriesCollection) dataset;
        if (tsc.getSeriesCount() > 0) {
            timePeriodClass = tsc.getSeries(0).getTimePeriodClass();
        } else {
            timePeriodClass = org.jfree.data.time.Day.class;
        }
        periodaxis.setAutoRangeTimePeriodClass(timePeriodClass);
    }
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = null;
    if (StatsManager.CHARTTIMESERIES_WEEKDAY.equals(timePeriod)) {
        aperiodaxislabelinfo = new PeriodAxisLabelInfo[2];
        aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class,
                new SimpleDateFormat("E", locale));
        aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class,
                new SimpleDateFormat("d", locale));
    } else if (StatsManager.CHARTTIMESERIES_DAY.equals(timePeriod)) {
        aperiodaxislabelinfo = new PeriodAxisLabelInfo[3];
        aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class,
                new SimpleDateFormat("d", locale));
        aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class,
                new SimpleDateFormat("MMM", locale));
        aperiodaxislabelinfo[2] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class,
                new SimpleDateFormat("yyyy", locale));
    } else if (StatsManager.CHARTTIMESERIES_MONTH.equals(timePeriod)) {
        aperiodaxislabelinfo = new PeriodAxisLabelInfo[2];
        aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class,
                new SimpleDateFormat("MMM", locale));
        aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class,
                new SimpleDateFormat("yyyy", locale));
    } else if (StatsManager.CHARTTIMESERIES_YEAR.equals(timePeriod)) {
        aperiodaxislabelinfo = new PeriodAxisLabelInfo[1];
        aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class,
                new SimpleDateFormat("yyyy", locale));
    }
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    // date range
    if (firstDate != null || lastDate != null) {
        periodaxis.setAutoRange(false);
        if (firstDate != null) {
            if (StatsManager.CHARTTIMESERIES_MONTH.equals(timePeriod)
                    || StatsManager.CHARTTIMESERIES_YEAR.equals(timePeriod)) {
                periodaxis.setFirst(new org.jfree.data.time.Month(firstDate));
            } else {
                periodaxis.setFirst(new org.jfree.data.time.Day(firstDate));
            }
        }
        if (lastDate != null) {
            if (StatsManager.CHARTTIMESERIES_MONTH.equals(timePeriod)
                    || StatsManager.CHARTTIMESERIES_YEAR.equals(timePeriod)) {
                periodaxis.setLast(new org.jfree.data.time.Month(lastDate));
            } else {
                periodaxis.setLast(new org.jfree.data.time.Day(lastDate));
            }
        }
    }
    periodaxis.setTickMarkOutsideLength(0.0F);
    plot.setDomainAxis(periodaxis);

    // set outline
    AbstractXYItemRenderer renderer = (AbstractXYItemRenderer) plot.getRenderer();
    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) renderer;
        r.setDrawSeriesLineAsPath(true);
        r.setShapesVisible(true);
        r.setShapesFilled(true);
    } else if (renderer instanceof XYBarRenderer) {
        //XYBarRenderer r = (XYBarRenderer) renderer;
        ClusteredXYBarRenderer r = new ClusteredXYBarRenderer();
        r.setDrawBarOutline(true);
        if (smallFontInDomainAxis && !canUseNormalFontSize(width))
            r.setMargin(0.05);
        else
            r.setMargin(0.10);
        plot.setRenderer(r);
        renderer = r;
    }

    // item labels
    if (itemLabelsVisible) {
        plot.getRangeAxis().setUpperMargin(0.2);
        renderer.setItemLabelGenerator(new XYItemLabelGenerator() {
            private static final long serialVersionUID = 1L;

            public String generateLabel(XYDataset dataset, int series, int item) {
                Number n = dataset.getY(series, item);
                if (n.doubleValue() != 0)
                    return n.toString();
                return "";
            }

        });
        renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
        renderer.setItemLabelsVisible(true);
    }

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        LOG.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private byte[] generatePieChart(String siteId, PieDataset dataset, int width, int height, boolean render3d,
        float transparency, boolean smallFontInDomainAxis) {
    JFreeChart chart = null;
    if (render3d)
        chart = ChartFactory.createPieChart3D(null, dataset, false, false, false);
    else/*from   w  ww .jav  a2s.  c  om*/
        chart = ChartFactory.createPieChart(null, dataset, false, false, false);
    PiePlot plot = (PiePlot) chart.getPlot();

    // set start angle (135 or 150 deg so minor data has more space on the left)
    plot.setStartAngle(150D);

    // set transparency
    plot.setForegroundAlpha(transparency);

    // set background
    chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));
    plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));

    // fix border offset      
    chart.setPadding(new RectangleInsets(5, 5, 5, 5));
    plot.setInsets(new RectangleInsets(1, 1, 1, 1));
    // set chart border
    plot.setOutlinePaint(null);
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set antialias
    chart.setAntiAlias(true);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        LOG.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:beproject.MainGUI.java

void createTimeLine() throws SQLException {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    getTimeLineData(dataset);//from w w  w. ja  va  2 s .  c o  m
    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Tweet Count");
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesStroke(1, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    domain.setAutoRange(true);
    domain.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2, Regression.sdf));
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    range.setTickLabelsVisible(true);

    plot.setDomainGridlinesVisible(false);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelsVisible(true);

    JFreeChart liveTweetAnalysisChart = new JFreeChart("Rate of tweets per hour",
            new Font("Tahoma", Font.BOLD, 24), plot, true);
    liveTweetAnalysisChart.setBorderVisible(false);

    ChartUtilities.applyCurrentTheme(liveTweetAnalysisChart);

    domain.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    range.setTickMarksVisible(false);
    range.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    domain.setTickMarksVisible(false);
    liveTweetAnalysisChart.setPadding(RectangleInsets.ZERO_INSETS);

    ChartPanel liveTweetAnalysisChartPanel = new ChartPanel(liveTweetAnalysisChart, true);
    liveTweetAnalysisChartPanel.setBorder(null);

    if (timeLineChart == null) {
        timeLineChart = liveTweetAnalysisChartPanel;
    } else {
        timeLinePanel.remove(timeLineChart);
        timeLineChart = liveTweetAnalysisChartPanel;
    }
    timeLinePanel.add(timeLineChart);
    timeLinePanel.validate();
}

From source file:beproject.MainGUI.java

void liveTweetAnalysis() {
    new DataGenerator(1000).start();
    rate = new TimeSeries("Total count", Second.class);
    rate.setMaximumItemAge(15);// w  w  w  . j a  v a  2 s .c o m
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(rate);
    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Tweet Count");
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesStroke(1, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    range.setTickLabelsVisible(true);

    plot.setDomainGridlinesVisible(false);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelsVisible(true);

    JFreeChart liveTweetAnalysisChart = new JFreeChart("Tweets Per Second", new Font("Tahoma", Font.BOLD, 24),
            plot, true);
    liveTweetAnalysisChart.setBorderVisible(false);
    liveTweetAnalysisChart.setBorderPaint(null);

    ChartUtilities.applyCurrentTheme(liveTweetAnalysisChart);

    domain.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    range.setTickMarksVisible(false);
    range.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    domain.setTickMarksVisible(false);
    liveTweetAnalysisChart.setPadding(RectangleInsets.ZERO_INSETS);

    ChartPanel liveTweetAnalysisChartPanel = new ChartPanel(liveTweetAnalysisChart, true);
    liveTweetAnalysisChartPanel.setBorder(null);

    liveTweetsAnalysisPanel.add(liveTweetAnalysisChartPanel, BorderLayout.CENTER);
    liveTweetsAnalysisPanel.validate();
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java

private JFreeChart updateBubbleChartChartWithCustUserData(
        Set<QuantDiseaseGroupsComparison> selectedComparisonList) {

    tooltipsProtNumberMap.clear();//from   ww  w  .  j a va 2  s  .  c  o  m
    DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();
    int counter = 0;
    int upper = -1;
    boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly();

    if (userCustomizedComparison.getComparProtsMap().size() > upper) {
        upper = userCustomizedComparison.getComparProtsMap().size();
    }

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {
        if (significantOnly) {
            int upperCounter = 0;
            for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) {
                if (qp == null) {
                    continue;
                }

                if (qp.getSignificantTrindCategory() == 2) {
                    continue;
                }

                upperCounter++;
            }
            if (upperCounter > upper) {
                upper = upperCounter;
            }

        } else {
            if (qc.getComparProtsMap() == null) {
                System.out.println("null qc " + qc.getComparisonHeader());

            }
            if (qc.getComparProtsMap().size() > upper) {
                upper = qc.getComparProtsMap().size();
            }
        }

    }

    final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>();
    Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor,
            new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE };
    double[] tempWidthValue = new double[8];

    double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI };
    seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE,
            Color.WHITE, Color.WHITE });
    defaultxyzdataset.addSeries("   ", seriesValuesI);

    for (String key : userCustomizedComparison.getComparProtsMap().keySet()) {
        userCustomizedComparison.getComparProtsMap().get(key).updateLabelLayout();

        {
            tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key).getSignificantTrindCategory()
                    + 1] = tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key)
                            .getSignificantTrindCategory() + 1] + 1;
        }
    }
    int length = 0;
    if (upper < 10) {
        upper = 10;
    }
    double[] tooltipNumbess = new double[tempWidthValue.length];
    System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length);
    this.tooltipsProtNumberMap.put(userCustomizedComparison.getComparisonHeader(), tooltipNumbess);
    for (int z = 0; z < tempWidthValue.length; z++) {
        if (tempWidthValue[z] > 0) {
            tempWidthValue[z] = scaleValues(tempWidthValue[z], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05);
            length++;
        }

    }
    double[] yAxisValue = new double[length];
    double[] xAxisValue = new double[length];
    double[] widthValue = new double[length];
    Color[] serColorArr = new Color[length];
    length = 0;

    for (int z = 0; z < tempWidthValue.length; z++) {
        if (tempWidthValue[z] > 0) {
            xAxisValue[length] = z;
            yAxisValue[length] = counter + 1;
            widthValue[length] = tempWidthValue[z];
            serColorArr[length] = dataColor[z];
            length++;
        }

    }

    if (length == 1 && selectedComparisonList.size() == 1) {
        widthValue[0] = 1;
    }
    seriousColorMap.put(++counter, serColorArr);

    double[][] seriesValues = { yAxisValue, xAxisValue, widthValue };
    defaultxyzdataset.addSeries(userCustomizedComparison.getComparisonHeader(), seriesValues);

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {

        tempWidthValue = new double[8];
        if (qc.getComparProtsMap() == null) {
            continue;
        }

        for (String key : qc.getComparProtsMap().keySet()) {
            qc.getComparProtsMap().get(key).updateLabelLayout();

            if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2
                    || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) {
                tempWidthValue[3] = 0;
                tempWidthValue[6] = 0;
            } else {
                tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory()
                        + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1]
                                + 1;
            }
        }
        if (tempWidthValue[3] > 0 && tempWidthValue[6] >= 0) {
            stableColor = new Color(1, 141, 244);

        } else {
            stableColor = Color.decode("#b5babb");
        }
        tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6];
        tempWidthValue[6] = 0;
        dataColor[3] = stableColor;
        length = 0;
        if (upper < 10) {
            upper = 10;
        }
        tooltipNumbess = new double[tempWidthValue.length];
        System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length);
        this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess);
        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05);
                length++;
            }

        }
        yAxisValue = new double[length];
        xAxisValue = new double[length];
        widthValue = new double[length];
        serColorArr = new Color[length];
        length = 0;

        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                xAxisValue[length] = x;
                yAxisValue[length] = counter + 1;
                widthValue[length] = tempWidthValue[x];
                serColorArr[length] = dataColor[x];
                length++;
            }

        }

        if (length == 1 && selectedComparisonList.size() == 1) {
            widthValue[0] = 1;
        }
        seriousColorMap.put(counter + 1, serColorArr);

        seriesValues = new double[][] { yAxisValue, xAxisValue, widthValue };
        defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues);

        counter++;
    }

    double[] yAxisValueII = new double[0];
    double[] xAxisValueII = new double[0];
    double[] widthValueII = new double[0];
    seriousColorMap.put(counter + 1, new Color[] {});
    double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII };
    defaultxyzdataset.addSeries(" ", seriesValuesII);

    final Color[] labelsColor = new Color[] { Color.WHITE, new Color(80, 183, 71), Color.LIGHT_GRAY,
            new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.WHITE };
    Font font = new Font("Verdana", Font.BOLD, 13);
    SymbolAxis yAxis = new SymbolAxis(null,
            new String[] { "  ", "Decreased", " ", "Equal", " ", "Increased", "  " }) {
        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= labelsColor.length) {
                x = 0;
            }
            return labelsColor[x++];
        }
    };

    yAxis.setAutoRangeStickyZero(true);
    yAxis.setFixedAutoRange(8);
    yAxis.setTickLabelFont(font);
    yAxis.setGridBandsVisible(false);
    yAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperBound(6);

    String[] xAxisLabels = new String[selectedComparisonList.size() + 3];
    xAxisLabels[0] = "  ";
    final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 3];
    int x = 0;
    int maxLength = -1;
    //init labels color

    String updatedHeader = userCustomizedComparison.getComparisonHeader().split(" / ")[0].split("\n")[0] + " / "
            + userCustomizedComparison.getComparisonHeader().split(" / ")[1].split("\n")[0] + "";
    diseaseGroupslabelsColor[0] = Color.WHITE;
    diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get("UserData");
    xAxisLabels[x + 1] = updatedHeader + " (" + userCustomizedComparison.getDatasetIndexes().length + ")    ";
    if (xAxisLabels[x + 1].length() > maxLength) {
        maxLength = xAxisLabels[++x].length();
    }

    for (QuantDiseaseGroupsComparison comp : selectedComparisonList) {
        String header = comp.getComparisonHeader();
        updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0]
                + "";

        xAxisLabels[x + 1] = updatedHeader + " (" + comp.getDatasetIndexes().length + ")    ";
        if (xAxisLabels[x + 1].length() > maxLength) {
            maxLength = xAxisLabels[x + 1].length();
        }
        diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]);
        x++;

    }
    xAxisLabels[x + 1] = "   ";

    SymbolAxis xAxis;
    final boolean finalNum;
    finalNum = maxLength > 30 && selectedComparisonList.size() > 4;

    xAxis = new SymbolAxis(null, xAxisLabels) {

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= diseaseGroupslabelsColor.length) {
                x = 0;
            }
            return diseaseGroupslabelsColor[x++];
        }

        private final boolean localfinal = finalNum;

        @Override
        protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            if (localfinal) {
                setVerticalTickLabels(localfinal);
                return super.refreshTicksHorizontal(g2, dataArea, edge);
            }
            List ticks = new java.util.ArrayList();
            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);
            double size = getTickUnit().getSize();
            int count = calculateVisibleTickCount();
            double lowestTickValue = calculateLowestVisibleTickValue();
            double previousDrawnTickLabelPos = 0.0;
            double previousDrawnTickLabelLength = 0.0;
            if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
                for (int i = 0; i < count; i++) {
                    double currentTickValue = lowestTickValue + (i * size);
                    double xx = valueToJava2D(currentTickValue, dataArea, edge);
                    String tickLabel;
                    NumberFormat formatter = getNumberFormatOverride();
                    if (formatter != null) {
                        tickLabel = formatter.format(currentTickValue) + "  ";
                    } else {
                        tickLabel = valueToString(currentTickValue) + "  ";
                    }
                    // avoid to draw overlapping tick labels
                    Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics());
                    double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth();
                    boolean tickLabelsOverlapping = false;
                    if (i > 0) {
                        double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
                        if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) {
                            tickLabelsOverlapping = true;
                        }
                    }
                    if (tickLabelsOverlapping) {
                        setVerticalTickLabels(true);
                    } else {
                        // remember these values for next comparison
                        previousDrawnTickLabelPos = xx;
                        previousDrawnTickLabelLength = tickLabelLength;
                    }
                    TextAnchor anchor;
                    TextAnchor rotationAnchor;
                    double angle = 0.0;
                    if (isVerticalTickLabels()) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                        if (edge == RectangleEdge.TOP) {
                            angle = 76.5;
                        } else {
                            angle = -76.5;
                        }
                    } else {
                        if (edge == RectangleEdge.TOP) {
                            anchor = TextAnchor.BOTTOM_CENTER;
                            rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        } else {
                            anchor = TextAnchor.TOP_CENTER;
                            rotationAnchor = TextAnchor.TOP_CENTER;
                        }
                    }
                    Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                            angle);

                    ticks.add(tick);
                }
            }
            return ticks;
        }
    };

    //        }
    xAxis.setTickLabelFont(font);
    xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20));
    xAxis.setAutoRangeStickyZero(true);
    xAxis.setAutoRangeStickyZero(true);
    xAxis.setTickMarksVisible(false);
    xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1);
    xAxis.setGridBandsVisible(false);
    xAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS;

    XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) {
        private int counter = 0;
        private int localSerious = -1;
        private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap;

        @Override
        public Paint getSeriesPaint(int series) {
            if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) {
                counter = 0;
                isNewImge = false;
            }
            localSerious = series;
            Color c = localSeriousColorMap.get(series)[counter];
            counter++;

            return c;
        }

    };

    XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) {
        @Override
        protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) {
            try {
                if (!ticks.isEmpty()) {
                    ticks.remove(0);
                }
                if (!ticks.isEmpty()) {
                    ticks.remove(ticks.size() - 1);
                }
            } catch (Exception e) {
            }
            super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates.
        }

        //            private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")};
        //
        //            private final Font font = new Font("Verdana", Font.PLAIN, 12);
        //            private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."};
        //
        //            @Override
        //            public LegendItemCollection getLegendItems() {
        //                LegendItemCollection legendItemCollection = new LegendItemCollection();
        //                for (int i = 0; i < labelsColor.length; i++) {
        //                    LegendItem item = new LegendItem(labels[i], labelsColor[i]);
        //                    item.setLabelFont(font);
        //                    legendItemCollection.add(item);
        //
        //                }
        //
        //                return legendItemCollection;//To change body of generated methods, choose Tools | Templates.
        //            }
    };

    JFreeChart generatedChart = new JFreeChart(xyplot) {

    };
    xyplot.setOutlineVisible(false);
    LegendTitle legend = generatedChart.getLegend();
    legend.setVisible(false);
    xyplot.setBackgroundPaint(Color.WHITE);
    generatedChart.setBackgroundPaint(Color.WHITE);
    generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart);
    return generatedChart;

}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java

private JFreeChart updateBubbleChartChart(Set<QuantDiseaseGroupsComparison> selectedComparisonList) {

    if (userCustomizedComparison != null) {
        return updateBubbleChartChartWithCustUserData(selectedComparisonList);
    }/*from   ww  w .  j  a v a 2s.co m*/
    tooltipsProtNumberMap.clear();
    DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();
    int counter = 0;
    int upper = -1;
    boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly();

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {
        if (significantOnly) {
            int upperCounter = 0;
            for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) {
                if (qp == null) {
                    continue;
                }

                if (qp.getSignificantTrindCategory() == 2 || qp.getSignificantTrindCategory() == 5) {
                    continue;
                }

                upperCounter++;
            }
            if (upperCounter > upper) {
                upper = upperCounter;
            }

        } else {
            if (qc.getComparProtsMap() == null) {
                System.out.println("null qc " + qc.getComparisonHeader());

            }
            if (qc.getComparProtsMap().size() > upper) {
                upper = qc.getComparProtsMap().size();
            }
        }

    }

    final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>();
    Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor,
            new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE };

    double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI };
    seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE,
            Color.WHITE, Color.WHITE });
    defaultxyzdataset.addSeries("   ", seriesValuesI);

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {

        double[] tempWidthValue = new double[8];
        if (qc.getComparProtsMap() == null) {
            continue;
        }

        for (String key : qc.getComparProtsMap().keySet()) {
            qc.getComparProtsMap().get(key).updateLabelLayout();

            if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2
                    || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) {
                tempWidthValue[3] = 0;
                tempWidthValue[6] = 0;
            } else {
                tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory()
                        + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1]
                                + 1;
            }
        }

        if (tempWidthValue[3] > 0 && tempWidthValue[3] >= 0) {
            stableColor = new Color(1, 141, 244);

        } else {
            stableColor = Color.decode("#b5babb");

        }

        tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6];
        tempWidthValue[6] = 0;
        dataColor[3] = stableColor;

        int length = 0;
        if (upper < 10) {
            upper = 10;
        }

        double[] tooltipNumbess = new double[tempWidthValue.length];
        System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length);
        this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess);
        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[x] * 1.5 / upper, 0.05);
                length++;
            }

        }
        double[] yAxisValue = new double[length];
        double[] xAxisValue = new double[length];
        double[] widthValue = new double[length];
        Color[] serColorArr = new Color[length];
        length = 0;

        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                xAxisValue[length] = x;
                yAxisValue[length] = counter + 1;
                widthValue[length] = tempWidthValue[x];
                serColorArr[length] = dataColor[x];
                length++;
            }

        }

        if (length == 1 && selectedComparisonList.size() == 1) {
            widthValue[0] = 1;
        }
        seriousColorMap.put(counter + 1, serColorArr);

        double[][] seriesValues = { yAxisValue, xAxisValue, widthValue };
        defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues);
        counter++;
    }
    double[] yAxisValueII = new double[0];
    double[] xAxisValueII = new double[0];
    double[] widthValueII = new double[0];
    seriousColorMap.put(counter + 1, new Color[] {});
    double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII };
    defaultxyzdataset.addSeries(" ", seriesValuesII);

    final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY,
            new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.LIGHT_GRAY };
    Font font = new Font("Verdana", Font.BOLD, 13);
    SymbolAxis yAxis = new SymbolAxis(null,
            new String[] { "  ", "Decreased", " ", "Equal", " ", "Increased", "  " }) {

        int i = 0;

        @Override
        public RectangleInsets getTickLabelInsets() {
            //                System.out.println("at ---- super.getTickLabelInsets() " + super.getTickLabelInsets());
            //                if (i == 0) {
            //                    i++;
            //                    return new RectangleInsets(-5, -5, 0, 0);
            //                }else                   
            //                
            return super.getTickLabelInsets(); //To change body of generated methods, choose Tools | Templates.
        }

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= labelsColor.length) {
                x = 0;
            }
            return labelsColor[x++];
        }
    };
    yAxis.setAutoRangeStickyZero(true);
    yAxis.setFixedAutoRange(8);
    yAxis.setTickLabelFont(font);
    yAxis.setGridBandsVisible(false);
    yAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperBound(6);

    String[] xAxisLabels = new String[selectedComparisonList.size() + 2];
    int x = 0;
    xAxisLabels[x] = "";
    int maxLength = -1;
    //init labels color

    final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 2];
    diseaseGroupslabelsColor[x] = Color.WHITE;
    x++;

    for (QuantDiseaseGroupsComparison comp : selectedComparisonList) {
        String header = comp.getComparisonHeader();
        String updatedHeader = header.split(" / ")[0].split("\n")[0] + " / "
                + header.split(" / ")[1].split("\n")[0] + "";

        xAxisLabels[x] = updatedHeader + " (" + comp.getDatasetIndexes().length + ")    ";
        if (xAxisLabels[x].length() > maxLength) {
            maxLength = xAxisLabels[x].length();
        }
        diseaseGroupslabelsColor[x] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]);
        x++;

    }
    xAxisLabels[x] = "";
    diseaseGroupslabelsColor[x] = Color.WHITE;

    SymbolAxis xAxis;
    final boolean finalNum;
    finalNum = maxLength > 30 && selectedComparisonList.size() > 4;

    xAxis = new SymbolAxis(null, xAxisLabels) {

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= diseaseGroupslabelsColor.length) {
                x = 0;
            }
            return diseaseGroupslabelsColor[x++];
        }

        private final boolean localfinal = finalNum;

        @Override
        protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            if (localfinal) {
                setVerticalTickLabels(localfinal);
                return super.refreshTicksHorizontal(g2, dataArea, edge);
            }
            List ticks = new java.util.ArrayList();
            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);
            double size = getTickUnit().getSize();
            int count = calculateVisibleTickCount();
            double lowestTickValue = calculateLowestVisibleTickValue();
            double previousDrawnTickLabelPos = 0.0;
            double previousDrawnTickLabelLength = 0.0;
            if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
                for (int i = 0; i < count; i++) {
                    double currentTickValue = lowestTickValue + (i * size);
                    double xx = valueToJava2D(currentTickValue, dataArea, edge);
                    String tickLabel;
                    NumberFormat formatter = getNumberFormatOverride();
                    if (formatter != null) {
                        tickLabel = formatter.format(currentTickValue) + "  ";
                    } else {
                        tickLabel = valueToString(currentTickValue) + "  ";
                    }
                    // avoid to draw overlapping tick labels
                    Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics());
                    double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth();
                    boolean tickLabelsOverlapping = false;
                    if (i > 0) {
                        double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
                        if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) {
                            tickLabelsOverlapping = true;
                        }
                    }
                    if (tickLabelsOverlapping) {
                        setVerticalTickLabels(true);
                    } else {
                        // remember these values for next comparison
                        previousDrawnTickLabelPos = xx;
                        previousDrawnTickLabelLength = tickLabelLength;
                    }
                    TextAnchor anchor;
                    TextAnchor rotationAnchor;
                    double angle = 0.0;
                    if (isVerticalTickLabels()) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                        if (edge == RectangleEdge.TOP) {
                            angle = 76.5;
                        } else {
                            angle = -76.5;
                        }
                    } else {
                        if (edge == RectangleEdge.TOP) {
                            anchor = TextAnchor.BOTTOM_CENTER;
                            rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        } else {
                            anchor = TextAnchor.TOP_CENTER;
                            rotationAnchor = TextAnchor.TOP_CENTER;
                        }
                    }
                    Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                            angle);

                    ticks.add(tick);
                }
            }
            return ticks;
        }
    };

    //        }
    xAxis.setTickLabelFont(font);
    xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20));
    xAxis.setAutoRangeStickyZero(true);
    xAxis.setTickMarksVisible(false);
    xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1);

    xAxis.setGridBandsVisible(false);
    xAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS;

    XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) {
        private int counter = 0;
        private int localSerious = -1;
        private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap;

        @Override
        public Paint getSeriesPaint(int series) {
            if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) {
                counter = 0;
                isNewImge = false;
            }
            localSerious = series;
            Color c = localSeriousColorMap.get(series)[counter];
            counter++;

            return c;
        }

    };

    XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) {

        @Override
        protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) {
            try {
                if (!ticks.isEmpty()) {
                    ticks.remove(0);
                }
                if (!ticks.isEmpty()) {
                    ticks.remove(ticks.size() - 1);
                }
            } catch (Exception e) {
            }
            super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates.
        }

        //            private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")};
        //
        //            private final Font font = new Font("Verdana", Font.PLAIN, 12);
        //            private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."};
        //
        //            @Override
        //            public LegendItemCollection getLegendItems() {
        //                LegendItemCollection legendItemCollection = new LegendItemCollection();
        //                for (int i = 0; i < labelsColor.length; i++) {
        //                    LegendItem item = new LegendItem(labels[i], labelsColor[i]);
        //                    item.setLabelFont(font);
        //
        //                    legendItemCollection.add(item);
        //
        //                }
        //
        //                return legendItemCollection;//To change body of generated methods, choose Tools | Templates.
        //            }
    };

    JFreeChart generatedChart = new JFreeChart(xyplot) {

    };

    xyplot.setOutlineVisible(false);
    LegendTitle legend = generatedChart.getLegend();

    legend.setVisible(false);
    //        legend.setMargin(20, 0, 0, 0);
    ////        legend.setBorder(1, 1, 1, 1);
    //        legend.setFrame(new BlockBorder(1, 0, 1, 0, Color.LIGHT_GRAY));

    //        generatedChart.removeLegend();
    //        xyplot.setForegroundAlpha(0.65F);
    xyplot.setBackgroundPaint(Color.WHITE);

    generatedChart.setBackgroundPaint(Color.WHITE);

    generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart);
    //        exporter.writeChartToPDFFile(generatedChart, 595, 842, "bublechart.pdf");
    return generatedChart;

}

From source file:org.gbif.portal.web.controller.dataset.IndexingHistoryController.java

/**
 * Create a time series graphic to display indexing processes.
 * //  w  w  w  .  ja v a2  s. co m
 * @param dataProvider
 * @param dataResource
 * @param activities
 * @param fileNamePrefix
 * @return
 */
public String timeSeriesTest(DataProviderDTO dataProvider, DataResourceDTO dataResource,
        List<LoggedActivityDTO> loggedActivities, String fileNamePrefix, int minProcessingTimeToRender) {

    List<LoggedActivityDTO> activities = new ArrayList<LoggedActivityDTO>();
    for (LoggedActivityDTO la : loggedActivities) {
        if (la.getDataResourceKey() != null && la.getDataResourceName() != null && la.getEventName() != null)
            activities.add(la);
    }

    //if no activities to render, return
    if (activities.isEmpty())
        return null;

    Map<String, Integer> drActualCount = new HashMap<String, Integer>();
    Map<String, Integer> drCount = new HashMap<String, Integer>();

    //record the actual counts
    for (LoggedActivityDTO laDTO : activities) {
        if (laDTO.getStartDate() != null && laDTO.getEndDate() != null
                && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) {
            if (drActualCount.get(laDTO.getDataResourceName()) == null) {
                drActualCount.put(laDTO.getDataResourceName(), new Integer(4));
                drCount.put(laDTO.getDataResourceName(), new Integer(0));
            } else {
                Integer theCount = drActualCount.get(laDTO.getDataResourceName());
                theCount = new Integer(theCount.intValue() + 4);
                drActualCount.remove(laDTO.getDataResourceName());
                drActualCount.put(laDTO.getDataResourceName(), theCount);
            }
        }
    }

    StringBuffer fileNameBuffer = new StringBuffer(fileNamePrefix);
    if (dataResource != null) {
        fileNameBuffer.append("-resource-");
        fileNameBuffer.append(dataResource.getKey());
    } else if (dataProvider != null) {
        fileNameBuffer.append("-provider-");
        fileNameBuffer.append(dataProvider.getKey());
    }
    fileNameBuffer.append(".png");

    String fileName = fileNameBuffer.toString();
    String filePath = System.getProperty("java.io.tmpdir") + File.separator + fileName;

    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName;
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    boolean generateChart = false;

    int count = 1;
    int dataResourceCount = 1;

    Collections.sort(activities, new Comparator<LoggedActivityDTO>() {
        public int compare(LoggedActivityDTO o1, LoggedActivityDTO o2) {
            if (o1 == null || o2 == null || o1.getDataResourceKey() != null || o2.getDataResourceKey() != null)
                return -1;
            return o1.getDataResourceKey().compareTo(o2.getDataResourceKey());
        }
    });

    String currentDataResourceKey = activities.get(0).getDataResourceKey();

    for (LoggedActivityDTO laDTO : activities) {
        if (laDTO.getStartDate() != null && laDTO.getEndDate() != null
                && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) {

            if (currentDataResourceKey != null && !currentDataResourceKey.equals(laDTO.getDataResourceKey())) {
                dataResourceCount++;
                count = count + 1;
                currentDataResourceKey = laDTO.getDataResourceKey();
            }
            TimeSeries s1 = new TimeSeries(laDTO.getDataResourceName(), "Process time period",
                    laDTO.getEventName(), Hour.class);
            s1.add(new Hour(laDTO.getStartDate()), count);
            s1.add(new Hour(laDTO.getEndDate()), count);
            dataset.addSeries(s1);
            generateChart = true;
        }
    }

    if (!generateChart)
        return null;

    // create a pie chart...
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);

    XYPlot plot = chart.getXYPlot();
    plot.setWeight(10);
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setRange(0, drCount.size() + 1);
    plot.getRangeAxis().setAxisLineVisible(false);
    plot.getRangeAxis().setAxisLinePaint(Color.WHITE);
    plot.setDomainCrosshairValue(1);
    plot.setRangeGridlinesVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setLabel("datasets");

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    MyXYItemLabelGenerator labelGenerator = new MyXYItemLabelGenerator();
    labelGenerator.setDataResourceActualCount(drActualCount);
    labelGenerator.setDataResourceCount(drCount);
    renderer.setItemLabelGenerator(labelGenerator);

    List<TimeSeries> seriesList = dataset.getSeries();
    for (TimeSeries series : seriesList) {
        if (((String) series.getRangeDescription()).startsWith("extraction")) {
            renderer.setSeriesPaint(seriesList.indexOf(series), Color.RED);
        } else {
            renderer.setSeriesPaint(seriesList.indexOf(series), Color.BLUE);
        }
        renderer.setSeriesStroke(seriesList.indexOf(series), new BasicStroke(7f));
    }

    int imageHeight = 30 * dataResourceCount;
    if (imageHeight < 100) {
        imageHeight = 100;
    } else {
        imageHeight = imageHeight + 100;
    }

    final BufferedImage image = new BufferedImage(900, imageHeight, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 900, imageHeight);

    // draw
    chart.draw(g2, chartArea, null, null);

    //styling
    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    try {
        FileOutputStream fOut = new FileOutputStream(filePath);
        ChartUtilities.writeChartAsPNG(fOut, chart, 900, imageHeight);
        return fileName;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

/**
 *
 *//*from   w w  w .  ja  v a  2 s . c  om*/
protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException {
    ChartSettings chartSettings = getChartSettings();
    setChartBackground(jfreeChart);
    setChartTitle(jfreeChart);
    setChartSubtitles(jfreeChart);
    setChartLegend(jfreeChart);
    setChartBorder(jfreeChart);

    Boolean chartAntiAlias = chartSettings.getAntiAlias();
    if (chartAntiAlias != null)
        jfreeChart.setAntiAlias(chartAntiAlias.booleanValue());

    Boolean textAntiAlias = chartSettings.getTextAntiAlias();
    if (textAntiAlias != null)
        jfreeChart.setTextAntiAlias(textAntiAlias.booleanValue());

    RectangleInsets padding = chartSettings.getPadding();
    if (padding != null) {
        jfreeChart.setPadding(padding);//FIXMETHEME consider using linebox
    }
    configurePlot(jfreeChart.getPlot(), jrPlot);
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

/**
 *
 *///  w ww.  ja  va2  s  .  co  m
protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException {
    ChartSettings chartSettings = getChartSettings();
    setChartBackground(jfreeChart);
    setChartTitle(jfreeChart);
    setChartSubtitles(jfreeChart);
    setChartLegend(jfreeChart);
    setChartBorder(jfreeChart);

    Boolean chartAntiAlias = chartSettings.getAntiAlias();
    if (chartAntiAlias != null)
        jfreeChart.setAntiAlias(chartAntiAlias);

    Boolean textAntiAlias = chartSettings.getTextAntiAlias();
    if (textAntiAlias != null)
        jfreeChart.setTextAntiAlias((boolean) textAntiAlias);

    RectangleInsets padding = chartSettings.getPadding();
    if (padding != null) {
        jfreeChart.setPadding(padding);//FIXMETHEME consider using linebox
    }
    configurePlot(jfreeChart.getPlot(), jrPlot);
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

/**
 *
 *///  w w  w . ja v  a 2 s .  c o m
protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException {
    Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.BASEFONT_SIZE);

    setChartBackground(jfreeChart);
    setChartTitle(jfreeChart, defaultBaseFontSize);
    setChartSubtitles(jfreeChart, defaultBaseFontSize);
    setChartLegend(jfreeChart, defaultBaseFontSize);
    setChartBorder(jfreeChart);

    Boolean isAntiAlias = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.CHART_ANTI_ALIAS);
    if (isAntiAlias != null)
        jfreeChart.setAntiAlias(isAntiAlias.booleanValue());

    Double padding = (Double) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_PADDING);
    UnitType unitType = (UnitType) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.UNIT_TYPE);
    if (padding != null && unitType != null) {
        double chartPadding = padding.doubleValue();
        jfreeChart.setPadding(
                new RectangleInsets(unitType, chartPadding, chartPadding, chartPadding, chartPadding));
    }
    configurePlot(jfreeChart.getPlot(), jrPlot);
}