Search in sources :

Example 1 with JFreeChart

use of org.jfree.chart.JFreeChart in project GT by Tencent.

the class CPURealTimeChart method createChart.

@Override
public JFreeChart createChart() {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("CPU实时曲线图", "时间", "CPU%", dataset, true, true, false);
    //设置,不然中文会存在乱码
    chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));
    XYPlot xyPlot = (XYPlot) chart.getXYPlot();
    ValueAxis domainAxis = xyPlot.getDomainAxis();
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 14));
    domainAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));
    rangeAxis.setLabelFont(new Font("宋体", Font.BOLD, 14));
    rangeAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));
    return chart;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 2 with JFreeChart

use of org.jfree.chart.JFreeChart in project GT by Tencent.

the class PieChart method createChart.

private JFreeChart createChart() {
    this.dataset = new DefaultPieDataset();
    final JFreeChart chart = ChartFactory.createPieChart("内存构成分析", this.dataset, true, true, false);
    chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}"));
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 3 with JFreeChart

use of org.jfree.chart.JFreeChart in project hudson-2.x by hudson.

the class LoadStatisticsTest method testGraph.

public void testGraph() throws IOException {
    LoadStatistics ls = new LoadStatistics(0, 0) {

        public int computeIdleExecutors() {
            throw new UnsupportedOperationException();
        }

        public int computeTotalExecutors() {
            throw new UnsupportedOperationException();
        }

        public int computeQueueLength() {
            throw new UnsupportedOperationException();
        }
    };
    for (int i = 0; i < 50; i++) {
        ls.totalExecutors.update(4);
        ls.busyExecutors.update(3);
        ls.queueLength.update(3);
    }
    for (int i = 0; i < 50; i++) {
        ls.totalExecutors.update(0);
        ls.busyExecutors.update(0);
        ls.queueLength.update(1);
    }
    JFreeChart chart = ls.createTrendChart(TimeScale.SEC10).createChart();
    BufferedImage image = chart.createBufferedImage(400, 200);
    File tempFile = File.createTempFile("chart-", "png");
    FileOutputStream os = new FileOutputStream(tempFile);
    try {
        ImageIO.write(image, "PNG", os);
    } finally {
        IOUtils.closeQuietly(os);
        tempFile.delete();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) JFreeChart(org.jfree.chart.JFreeChart) BufferedImage(java.awt.image.BufferedImage)

Example 4 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 5 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)

Aggregations

JFreeChart (org.jfree.chart.JFreeChart)175 XYPlot (org.jfree.chart.plot.XYPlot)38 NumberAxis (org.jfree.chart.axis.NumberAxis)24 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 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Paint (java.awt.Paint)10 ValueAxis (org.jfree.chart.axis.ValueAxis)10 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)10