Example usage for org.jfree.chart JFreeChart setBorderPaint

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

Introduction

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

Prototype

public void setBorderPaint(Paint paint) 

Source Link

Document

Sets the paint used to draw the chart border (if visible).

Usage

From source file:code.google.gclogviewer.GCLogViewer.java

private JFreeChart createLDSTrendChart(GCLogData data) {
    XYDataset ldsTrendDataset = createLDSTrendDataset(data);
    JFreeChart chart = ChartFactory.createXYLineChart("Live Data Size Trend", "Time(S)", "Size(K)",
            ldsTrendDataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(java.awt.Color.white);
    chart.setBorderVisible(true);//from w  ww.j  a v a2 s.  com
    chart.setBorderPaint(java.awt.Color.BLACK);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(java.awt.Color.lightGray);
    plot.setDomainGridlinePaint(java.awt.Color.white);
    plot.setRangeGridlinePaint(java.awt.Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    return chart;
}

From source file:code.google.gclogviewer.GCLogViewer.java

/**
 * create Memory Trend Chart/*from   ww  w .j  a v  a2  s.c  o m*/
 */
private JFreeChart createMemoryTrendChart(GCLogData data) {
    XYDataset memoryTrendDataset = createMemoryTrendDataset(data, null);
    JFreeChart chart = ChartFactory.createXYLineChart("Memory Trend", "Time(S)", "Memory Change(K)",
            memoryTrendDataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(java.awt.Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(java.awt.Color.BLACK);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(java.awt.Color.lightGray);
    plot.setDomainGridlinePaint(java.awt.Color.white);
    plot.setRangeGridlinePaint(java.awt.Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    return chart;
}

From source file:code.google.gclogviewer.GCLogViewer.java

private JFreeChart createPTOSTrendChart(GCLogData data) {
    XYDataset ldsTrendDataset = createPTOSTrendDataset(data);
    JFreeChart chart = ChartFactory.createXYLineChart("Promotion To Old Size Trend", "Time(S)", "Size(K)",
            ldsTrendDataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(java.awt.Color.white);
    chart.setBorderVisible(true);/*from   w  w  w . jav a  2  s.c o m*/
    chart.setBorderPaint(java.awt.Color.BLACK);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(java.awt.Color.lightGray);
    plot.setDomainGridlinePaint(java.awt.Color.white);
    plot.setRangeGridlinePaint(java.awt.Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    return chart;
}

From source file:GroupProject.OriginalChartUI.java

/**
 * The method to draw pie chart/*from  w w w. j  a  v a2 s  .co  m*/
 * @param pieChartData the data used in the pie chart
 * @param pieTitle the measurement of pie chart
 */
public void drawPieChart(Map<String, Long> pieChartData, String pieTitle) {

    String title = pieTitle;
    ArrayList<String> keyArrayList = new ArrayList<>();
    ArrayList<Long> valueArrayList = new ArrayList<>();
    ArrayList<Color> colorArrayList = new ArrayList<>();

    colorArrayList.add(new Color(222, 235, 247));
    colorArrayList.add(new Color(109, 166, 217));
    colorArrayList.add(new Color(155, 195, 230));
    colorArrayList.add(new Color(126, 146, 222));
    colorArrayList.add(new Color(96, 158, 218));
    colorArrayList.add(new Color(53, 132, 203));
    colorArrayList.add(new Color(46, 116, 180));
    colorArrayList.add(new Color(31, 77, 119));

    DefaultPieDataset dataset = new DefaultPieDataset();
    Set set = pieChartData.keySet();
    for (Map.Entry<String, Long> data : pieChartData.entrySet()) {
        String key = data.getKey();
        Long value = data.getValue();
        keyArrayList.add(key);
        valueArrayList.add(value);
    }
    for (int i = 0; i < valueArrayList.size(); i++) {
        dataset.setValue(keyArrayList.get(i), valueArrayList.get(i));
    }
    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset);
    chart.setBorderVisible(false);
    chart.setBorderPaint(new Color(255, 255, 255));
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    for (int i = 0; i < valueArrayList.size(); i++) {
        Color color = colorArrayList.get(i);
        plot.setSectionPaint(keyArrayList.get(i), color);
    }
    plot.setOutlineVisible(false);
    plot.setForegroundAlpha(0.6f);
    plot.setStartAngle(0);
    plot.setBackgroundPaint(new java.awt.Color(255, 255, 255));
    ChartPanel chartPanel = new ChartPanel(chart);
    chartDisplayPanel.removeAll();
    chartDisplayPanel.add(chartPanel, BorderLayout.CENTER);
    chartDisplayPanel.validate();
}

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

/**
 * Creates a Pie Chart based on map.//from w  w  w. java  2  s.  com
 *
 * @return the Pie Chart generated.
 */
public JFreeChart getPieChart(Map<String, Double> pieValues) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    for (String key : pieValues.keySet()) {
        dataset.setValue(key, pieValues.get(key));
    }

    JFreeChart chart = ChartFactory.createPieChart3D(null, // chart title
            dataset, // data
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);
    plot.setLabelGap(0.02);
    plot.setOutlinePaint(null);
    plot.setLabelLinksVisible(false);

    plot.setLabelGenerator(null);

    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));

    plot.setStartAngle(270);
    plot.setDirection(Rotation.ANTICLOCKWISE);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.33);

    return chart;
}

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeChart(JFreeChart jfchart, ChartParams params) {
    // title//from w  w  w.jav a  2 s .  co m
    if (params.get(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) {
        TextTitle title = new TextTitle(params.getString(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX));

        customizeTitle(title, params, ChartParams.TITLE_PREFIX);

        jfchart.setTitle(title);
    }

    // subtitle
    if (params.get(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) {
        TextTitle subtitle = new TextTitle(
                params.getString(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX));

        customizeTitle(subtitle, params, ChartParams.SUBTITLE_PREFIX);

        jfchart.addSubtitle(subtitle);
    }

    // legend
    LegendTitle legend = jfchart.getLegend();

    customizeLegend(legend, params);

    // anti-alias
    if (params.get(ChartParams.ANTI_ALIAS) != null) {
        jfchart.setAntiAlias(params.getBoolean(ChartParams.ANTI_ALIAS).booleanValue());
    }
    // background color
    if (params.get(ChartParams.BACKGROUND_COLOR) != null) {
        jfchart.setBackgroundPaint(params.getColor(ChartParams.BACKGROUND_COLOR));
    }

    // border
    if (params.get(ChartParams.BORDER_VISIBLE) != null
            && params.getBoolean(ChartParams.BORDER_VISIBLE).booleanValue()) {
        jfchart.setBorderVisible(true);
        if (params.get(ChartParams.BORDER_COLOR) != null) {
            jfchart.setBorderPaint(params.getColor(ChartParams.BORDER_COLOR));
        }
        if (params.get(ChartParams.BORDER_STROKE) != null) {
            jfchart.setBorderStroke(params.getStroke(ChartParams.BORDER_STROKE));
        }
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYDataset dataset = (XYDataset) datasets.getDatasets().get("1");

    final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend,
            false, false);/*from  w w  w .  j a v a  2s.c o  m*/
    sparkLineGraph.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    sparkLineGraph.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        sparkLineGraph.addSubtitle(subTitle);
    }

    sparkLineGraph.setBorderVisible(false);
    sparkLineGraph.setBorderPaint(Color.BLACK);
    XYPlot plot = sparkLineGraph.getXYPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(color);

    // calculate the last marker color
    Paint colorLast = getLastPointColor();

    // Calculate average, minimum and maximum to draw plot borders.
    boolean isFirst = true;
    double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
    int count = 0;
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        if (timeSeries.getValue(i) != null) {
            count++;
            if (isFirst) {
                min = timeSeries.getValue(i).doubleValue();
                max = timeSeries.getValue(i).doubleValue();
                isFirst = false;
            }
            double n = timeSeries.getValue(i).doubleValue();
            //calculate avg, min, max
            avg += n;
            if (n < min)
                min = n;
            if (n > max)
                max = n;
        }
    }
    // average
    avg = avg / (double) count;

    // calculate min and max between thresholds!
    boolean isFirst2 = true;
    double lb = 0, ub = 0;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        if (isFirst2 == true) {
            ub = thres.doubleValue();
            lb = thres.doubleValue();
            isFirst2 = false;
        }
        if (thres.doubleValue() > ub)
            ub = thres.doubleValue();
        if (thres.doubleValue() < lb)
            lb = thres.doubleValue();
    }

    plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2));

    addMarker(1, avg, Color.GRAY, 0.8f, plot);
    //addAvaregeSeries(series, plot);
    addPointSeries(timeSeries, plot);

    int num = 3;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        TargetThreshold targThres = thresholds.get(thres);
        Color color = Color.WHITE;
        if (targThres != null && targThres.getColor() != null) {
            color = targThres.getColor();
        }
        if (targThres.isVisible()) {
            addMarker(num++, thres.doubleValue(), color, 0.5f, plot);
        }
    }

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setUpperMargin(0.2);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);

    plot.getRenderer().setSeriesPaint(0, Color.BLACK);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        public boolean getItemShapeVisible(int _series, int item) {
            TimeSeriesDataItem tsdi = timeSeries.getDataItem(item);
            if (tsdi == null)
                return false;
            Month period = (Month) tsdi.getPeriod();
            int currMonth = period.getMonth();
            int currYear = period.getYearValue();
            int lastMonthFilled = lastMonth.getMonth();
            int lastYearFilled = lastMonth.getYearValue();
            boolean isLast = false;
            if (currYear == lastYearFilled && currMonth == lastMonthFilled) {
                isLast = true;
            }
            return isLast;
        }
    };
    renderer.setSeriesPaint(0, Color.decode("0x000000"));

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(colorLast);
    renderer.setBaseOutlinePaint(Color.BLACK);
    renderer.setUseOutlinePaint(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"),
                new DecimalFormat("0.###")) {
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0)
                    return "";
                String columnKey = (String) dataset.getColumnKey(column);
                int separator = columnKey.indexOf('-');
                String month = columnKey.substring(0, separator);
                String year = columnKey.substring(separator + 1);
                int monthNum = Integer.parseInt(month);
                if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                    if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                        return "";

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.MONTH, monthNum - 1);
                    SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                    return dataFormat.format(calendar.getTime());
                } else
                    return "" + monthNum;
            }
        });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage);
        collection.add(item);
        plot.setFixedLegendItems(collection);

    }

    plot.setRenderer(0, renderer);
    logger.debug("OUT");
    return sparkLineGraph;
}

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

/**
 * Generates a SparkLine Time Area Chart.
 * @param key/*w ww .  j a v a  2s .  c o  m*/
 * @param stats
 * @param startTime
 * @param endTime
 * @return chart
 */
private JFreeChart generateSparklineAreaChart(String key, String color, Statistic[] stats, long startTime,
        long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();

    XYDataset dataset = populateData(key, stats, startTime, endTime, dataPoints);

    JFreeChart chart = ChartFactory.createXYAreaChart(null, // chart title
            null, // xaxis label
            null, // yaxis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(1.0f);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);

    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);

    NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();

    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);

    NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);

    return chart;
}

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

/**
 * Generates a Sparkline Bar Graph./*from w ww .  j  av a 2s  .  c o  m*/
 *
 * @param def the key of the statistic object.
 * @return the generated chart.
 */
public JFreeChart generateSparklineBarGraph(String key, String color, Statistic[] def, long startTime,
        long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();

    IntervalXYDataset dataset = (IntervalXYDataset) populateData(key, def, startTime, endTime, dataPoints);
    JFreeChart chart = ChartFactory.createXYBarChart(null, // chart title
            null, // domain axis label
            true, null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);

    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);

    ValueAxis xAxis = chart.getXYPlot().getDomainAxis();

    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);

    ValueAxis yAxis = chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);

    return chart;
}