Search in sources :

Example 91 with JFreeChart

use of org.jfree.chart.JFreeChart in project opennms by OpenNMS.

the class ChartUtils method getBarChart.

/**
 * Helper method that returns the JFreeChart to an output stream written in JPEG format.
 *
 * @param chartName a {@link java.lang.String} object.
 * @param out a {@link java.io.OutputStream} object.
 * @throws java.io.IOException if any.
 * @throws java.sql.SQLException if any.
 */
public static void getBarChart(String chartName, OutputStream out) throws IOException, SQLException {
    BarChart chartConfig = getBarChartConfigByName(chartName);
    JFreeChart chart = getBarChart(chartName);
    ImageSize imageSize = chartConfig.getImageSize();
    int hzPixels;
    int vtPixels;
    if (imageSize == null) {
        hzPixels = 400;
        vtPixels = 400;
    } else {
        hzPixels = imageSize.getHzSize().getPixels();
        vtPixels = imageSize.getVtSize().getPixels();
    }
    ChartUtilities.writeChartAsJPEG(out, chart, hzPixels, vtPixels);
}
Also used : ImageSize(org.opennms.netmgt.config.charts.ImageSize) BarChart(org.opennms.netmgt.config.charts.BarChart) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint)

Example 92 with JFreeChart

use of org.jfree.chart.JFreeChart in project violations-plugin by jenkinsci.

the class SeverityTypeDataSet method createChart.

/**
 * Create a JFree chart for this dataset.
 *
 * @return the chart.
 */
public JFreeChart createChart() {
    CategoryDataset dataset = buildDataSet();
    JFreeChart chart = // chart
    ChartFactory.createStackedAreaChart(// chart
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(ALPHA);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    }
    StackedAreaRenderer renderer = new StackedAreaRenderer2();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(2, RED);
    renderer.setSeriesPaint(1, VIOLET);
    renderer.setSeriesPaint(0, YELLOW);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
    return chart;
}
Also used : ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 93 with JFreeChart

use of org.jfree.chart.JFreeChart in project n2a by frothga.

the class Plot method createGraphPanel.

public JPanel createGraphPanel() {
    XYDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    return new ChartPanelDrag(chart);
}
Also used : XYDataset(org.jfree.data.xy.XYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 94 with JFreeChart

use of org.jfree.chart.JFreeChart in project EnrichmentMapApp by BaderLab.

the class RadialHeatMapLayer method createChart.

@Override
protected JFreeChart createChart(final PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart(// chart title
    null, // data
    dataset, // include legend
    false, // tooltips
    false, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setCircular(true);
    plot.setStartAngle(startAngle);
    plot.setDirection(rotation == Rotation.ANTICLOCKWISE ? org.jfree.util.Rotation.ANTICLOCKWISE : org.jfree.util.Rotation.CLOCKWISE);
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setInteriorGap(INTERIOR_GAP);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setBackgroundAlpha(0.0f);
    plot.setShadowPaint(TRANSPARENT_COLOR);
    plot.setShadowXOffset(0.0);
    plot.setShadowYOffset(0.0);
    plot.setLabelGenerator(showItemLabels ? new CustomPieSectionLabelGenerator(labels) : null);
    plot.setSimpleLabels(true);
    plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
    plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
    plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
    plot.setLabelShadowPaint(TRANSPARENT_COLOR);
    plot.setLabelPaint(labelColor);
    final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    Color upperColor = Color.BLUE;
    Color zeroColor = Color.WHITE;
    Color lowerColor = Color.RED;
    Color nanColor = DEFAULT_ITEM_BG_COLOR;
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        final int colorsSize = colors != null ? colors.size() : 0;
        if (colorsSize > 0)
            upperColor = colors.get(0);
        if (colorsSize > 1)
            zeroColor = colors.get(1);
        if (colorsSize > 2)
            lowerColor = colors.get(2);
        if (colorsSize > 3)
            nanColor = colors.get(3);
    }
    final List<?> keys = dataset.getKeys();
    final List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
    for (int i = 0; i < keys.size(); i++) {
        String k = (String) keys.get(i);
        Double v = values.size() > i ? values.get(i) : null;
        final Color c;
        if (v == null)
            c = nanColor;
        else
            c = ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor);
        plot.setSectionPaint(k, c);
        plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
        plot.setSectionOutlineStroke(k, stroke);
    }
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) CustomPieSectionLabelGenerator(org.baderlab.csplugins.enrichmentmap.style.charts.CustomPieSectionLabelGenerator) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 95 with JFreeChart

use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.

the class ChartController method getHistoryChart.

@RequestMapping(value = { "/history/data", "/history/data.png" }, method = RequestMethod.GET)
public void getHistoryChart(@RequestParam String de, @RequestParam String co, @RequestParam String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(defaultValue = "525", required = false) int width, @RequestParam(defaultValue = "300", required = false) int height, HttpServletResponse response) throws IOException, WebMessageException {
    DataElement dataElement = dataElementService.getDataElement(de);
    if (dataElement == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Data element does not exist: " + de));
    }
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(co);
    if (categoryOptionCombo == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + co));
    }
    DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo(cp);
    if (attributeOptionCombo == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + cp));
    }
    Period period = PeriodType.getPeriodFromIsoString(pe);
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Period does not exist: " + pe));
    }
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
    if (organisationUnit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist: " + ou));
    }
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", false);
    JFreeChart chart = chartService.getJFreeChartHistory(dataElement, categoryOptionCombo, attributeOptionCombo, period, organisationUnit, 13, i18nManager.getI18nFormat());
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) JFreeChart(org.jfree.chart.JFreeChart) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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