Example usage for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection

List of usage examples for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection

Introduction

In this page you can find the example usage for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection.

Prototype

public StandardEntityCollection() 

Source Link

Document

Constructs a new entity collection (initially empty).

Usage

From source file:eu.planets_project.tb.gui.backing.ExperimentBean.java

public String getResultChartUrl() {
    try {/* ww w  .  j  av  a  2  s. co  m*/
        ExperimentChartServlet ec = new ExperimentChartServlet();
        chart = ec.createWallclockChart("" + this.getExperiment().getEntityID());
        // Pick into the session...
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
                .getRequest();
        HttpSession session = request.getSession();
        //  Write the chart image to the temporary directory
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        this.graphId = ServletUtilities.saveChartAsPNG(chart, 600, 500, info, session);
        this.graphImageMap = ChartUtilities.getImageMap(graphId, info);
        this.graphUrl = request.getContextPath() + "/servlet/DisplayChart?filename=" + graphId;
        return this.graphUrl;
    } catch (Exception e) {
        log.error("Failure while generating graph: " + e);
        e.printStackTrace();
        return null;
    }
}

From source file:fr.paris.lutece.plugins.form.web.FormJspBean.java

/**
 * write in the http response the statistic graph of all response submit who verify the date filter
 *@param request the http request/*from www  .  j av a  2  s .co  m*/
 * @param response The http response
 *
 */
public void doGenerateGraph(HttpServletRequest request, HttpServletResponse response) {
    Plugin plugin = getPlugin();
    Locale locale = getLocale();
    ResponseFilter filter = new ResponseFilter();
    int nIdForm = -1;
    String strIdForm = request.getParameter(PARAMETER_ID_FORM);
    String strFistResponseDateFilter = request.getParameter(PARAMETER_FIRST_RESPONSE_DATE_FILTER);
    String strLastResponseDateFilter = request.getParameter(PARAMETER_LAST_RESPONSE_DATE_FILTER);
    String strTimesUnit = request.getParameter(PARAMETER_TIMES_UNIT);
    Timestamp tFistResponseDateFilter = null;
    Timestamp tLastResponseDateFilter = null;

    if (strFistResponseDateFilter != null) {
        tFistResponseDateFilter = FormUtils
                .getDateFirstMinute(DateUtil.formatDate(strFistResponseDateFilter, locale), locale);
    }

    if (strLastResponseDateFilter != null) {
        tLastResponseDateFilter = FormUtils
                .getDateLastMinute(DateUtil.formatDate(strLastResponseDateFilter, locale), locale);
    }

    if ((strIdForm != null) && !strIdForm.equals(EMPTY_STRING)) {
        try {
            nIdForm = Integer.parseInt(strIdForm);
        } catch (NumberFormatException ne) {
            AppLogService.error(ne);
        }
    }

    filter.setIdForm(nIdForm);
    filter.setDateFirst(tFistResponseDateFilter);
    filter.setDateLast(tLastResponseDateFilter);

    if (strTimesUnit != null) {
        if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_DAY)) {
            filter.setGroupbyDay(true);
        } else if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_WEEK)) {
            filter.setGroupbyWeek(true);
        } else if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_MONTH)) {
            filter.setGroupbyMonth(true);
        }
    } else {
        filter.setGroupbyDay(true);
        strTimesUnit = FormUtils.CONSTANT_GROUP_BY_DAY;
    }

    List<StatisticFormSubmit> listStatisticResult = FormSubmitHome.getStatisticFormSubmit(filter, plugin);

    String strNumberOfResponseAxisX = AppPropertiesService.getProperty(PROPERTY_NUMBER_RESPONSE_AXIS_X);
    int nNumberOfResponseAxisX = 10;

    try {
        nNumberOfResponseAxisX = Integer.parseInt(strNumberOfResponseAxisX);
    } catch (NumberFormatException ne) {
        AppLogService.error(ne);
    }

    List<StatisticFormSubmit> listStatisticGraph = new ArrayList<StatisticFormSubmit>();
    StatisticFormSubmit statisticFormSubmit;

    if (listStatisticResult.size() != 0) {
        for (int cpt = 0; cpt < nNumberOfResponseAxisX; cpt++) {
            statisticFormSubmit = new StatisticFormSubmit();
            statisticFormSubmit.setNumberResponse(0);
            statisticFormSubmit.setStatisticDate(FormUtils
                    .addStatisticInterval(listStatisticResult.get(0).getStatisticDate(), strTimesUnit, cpt));
            listStatisticGraph.add(statisticFormSubmit);
        }
    }

    for (StatisticFormSubmit statisticFormSubmitGraph : listStatisticGraph) {
        for (StatisticFormSubmit statisticFormSubmitResult : listStatisticResult) {
            if (FormUtils.sameDate(statisticFormSubmitGraph.getStatisticDate(),
                    statisticFormSubmitResult.getStatisticDate(), strTimesUnit)) {
                statisticFormSubmitGraph.setNumberResponse(statisticFormSubmitResult.getNumberResponse());
            }
        }
    }

    String strLabelAxisX = I18nService.getLocalizedString(PROPERTY_LABEL_AXIS_X, locale);
    String strLabelAxisY = I18nService.getLocalizedString(PROPERTY_LABEL_AXIS_Y, locale);

    JFreeChart chart = FormUtils.createXYGraph(listStatisticGraph, strLabelAxisX, strLabelAxisY, strTimesUnit);

    try {
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        BufferedImage chartImage = chart.createBufferedImage(600, 200, info);
        response.setContentType("image/PNG");

        PngEncoder encoder = new PngEncoder(chartImage, false, 0, 9);
        response.getOutputStream().write(encoder.pngEncode());
        response.getOutputStream().close();
    } catch (Exception e) {
        AppLogService.error(e);
    }
}