Search in sources :

Example 16 with JFreeChart

use of org.jfree.chart.JFreeChart in project openblocks by mikaelhg.

the class CLineGraph method getOutputPanel.

public ChartPanel getOutputPanel() {
    //we return a copy of the chart because we only want to show the
    //legend in the larger view of the graph
    //not the small runtime graph block view
    JFreeChart newChart = new JFreeChart(chart.getPlot());
    newChart.getLegend().setPosition(RectangleEdge.TOP);
    newChart.getLegend().setPadding(5, 5, 5, 5);
    newChart.setBackgroundPaint(background);
    output = new ChartPanel(newChart);
    return output;
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) JFreeChart(org.jfree.chart.JFreeChart)

Example 17 with JFreeChart

use of org.jfree.chart.JFreeChart in project Openfire by igniterealtime.

the class GraphEngine method createChart.

private JFreeChart createChart(String title, XYPlot plot) {
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(Color.white);
    return chart;
}
Also used : JFreeChart(org.jfree.chart.JFreeChart)

Example 18 with JFreeChart

use of org.jfree.chart.JFreeChart in project Openfire by igniterealtime.

the class GraphEngine method generateSparklineAreaChart.

/**
     * Generates a SparkLine Time Area Chart.
     * @param key
     * @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(// chart title
    null, // xaxis label
    null, // yaxis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    false, // URLs?
    false);
    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;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 19 with JFreeChart

use of org.jfree.chart.JFreeChart in project Openfire by igniterealtime.

the class GraphEngine method generateChart.

/**
     * Creates a chart.
     *
     * @param key
     * @param width
     * @param height
     * @param startTime
     * @param endTime
     * @param dataPoints
     * @return
     * @throws IOException
     */
public JFreeChart generateChart(String key, int width, int height, String color, long startTime, long endTime, int dataPoints) throws IOException {
    Statistic[] def = statsViewer.getStatistic(key);
    if (def == null) {
        return null;
    }
    XYDataset data = populateData(key, def, startTime, endTime, dataPoints);
    if (data == null) {
        return null;
    }
    JFreeChart chart;
    switch(def[0].getStatType()) {
        case count:
            chart = createTimeBarChart(null, color, def[0].getUnits(), data);
            break;
        default:
            chart = createTimeAreaChart(null, color, def[0].getUnits(), data);
    }
    return chart;
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 20 with JFreeChart

use of org.jfree.chart.JFreeChart in project Openfire by igniterealtime.

the class GraphEngine method generateSparklinesGraph.

/**
     * Generates a Sparkline type graph. Sparkline graphs
     * are "intense, simple, wordlike graphics" so named by Edward Tufte. The big
     * difference between the graph produced by this method compared to the
     * graph produced by the <code>generateGraph</code> method is that this one
     * produces graphs with no x-axis and no y-axis and is usually smaller in size.
     * @param key
     * @param width
     * @param height
     * @param startTime
     * @param endTime
     * @param dataPoints
     * @return
     * @throws IOException
     */
public byte[] generateSparklinesGraph(String key, int width, int height, String color, long startTime, long endTime, int dataPoints) throws IOException {
    Statistic[] def = statsViewer.getStatistic(key);
    if (def == null) {
        return null;
    }
    JFreeChart chart;
    switch(def[0].getStatType()) {
        case count:
            chart = generateSparklineBarGraph(key, color, def, startTime, endTime, dataPoints);
            break;
        default:
            chart = generateSparklineAreaChart(key, color, def, startTime, endTime, dataPoints);
    }
    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(true);
    return encoder.encode(chart.createBufferedImage(width, height, BufferedImage.BITMASK, null));
}
Also used : KeypointPNGEncoderAdapter(org.jfree.chart.encoders.KeypointPNGEncoderAdapter) Statistic(org.jivesoftware.openfire.stats.Statistic) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)178 XYPlot (org.jfree.chart.plot.XYPlot)40 NumberAxis (org.jfree.chart.axis.NumberAxis)26 Color (java.awt.Color)22 DateAxis (org.jfree.chart.axis.DateAxis)21 DecimalFormat (java.text.DecimalFormat)18 ChartPanel (org.jfree.chart.ChartPanel)17 XYSeries (org.jfree.data.xy.XYSeries)17 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)17 RectangleInsets (org.jfree.ui.RectangleInsets)17 NumberFormat (java.text.NumberFormat)16 CategoryAxis (org.jfree.chart.axis.CategoryAxis)16 CategoryPlot (org.jfree.chart.plot.CategoryPlot)16 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 HashMap (java.util.HashMap)12 ValueAxis (org.jfree.chart.axis.ValueAxis)12 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10