Search in sources :

Example 6 with ChartEntity

use of org.jfree.chart.entity.ChartEntity in project processdash by dtuma.

the class CGIChartBase method writeImageHtml.

private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException {
    String tooltip = getParameter("tooltip");
    if (!StringUtils.hasValue(tooltip))
        tooltip = resources.getHTML("More_Detail_Here_Instruction");
    String href = getParameter("href");
    if (StringUtils.hasValue(href)) {
        // create a copy of the entity collection, and place an entity for
        // the entire chart at the beginning of the list.  This will
        // make it appear last in the image map (which is important,
        // because browsers process the image map areas in the order that
        // they appear; having the entire chart area listed first would
        // obscure all of the other image map areas).
        EntityCollection entities = new StandardEntityCollection();
        entities.add(new ChartEntity(info.getChartArea(), tooltip, href));
        if (info.getEntityCollection() != null)
            entities.addAll(info.getEntityCollection());
        // area in the chart.
        for (Iterator i = entities.iterator(); i.hasNext(); ) {
            ChartEntity ce = (ChartEntity) i.next();
            // image map anyway, so they don't need to be adjusted
            if (ce.getToolTipText() == null && ce.getURLText() == null)
                continue;
            // for other entities, add a tooltip and a URL as needed.
            if (!StringUtils.hasValue(ce.getToolTipText()))
                ce.setToolTipText(tooltip);
            if (!StringUtils.hasValue(ce.getURLText()))
                ce.setURLText(href);
        }
        // install our modified version of the entity collection into
        // the chart info object, so it will be used when generating
        // the image map later.
        info.setEntityCollection(entities);
    }
    // write the image tag
    out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID + "\" usemap=\"#IMG" + imgID + '"');
    // have a URL we're pointing to.  Turn that border off.
    if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
        out.write(" border=\"0\"");
    // starting with the prefix "img", and copy them into the tag.
    for (Iterator i = parameters.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry e = (Map.Entry) i.next();
        String attrName = (String) e.getKey();
        if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) {
            out.write(" " + attrName.substring(3) + "=\"");
            out.write(HTMLUtils.escapeEntities(e.getValue().toString()));
            out.write('"');
        }
    }
    out.write(">");
    // finally, write the image map.  Note that we have to strip line
    // break characters from the resulting HTML, otherwise firefox seems
    // to decide that the <map> tag actually takes up space on the page
    String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip), new StandardURLTagFragmentGenerator());
    for (int i = 0; i < imageMapHtml.length(); i++) {
        char c = imageMapHtml.charAt(i);
        if (c != '\r' && c != '\n')
            out.write(c);
    }
    out.flush();
}
Also used : StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) EntityCollection(org.jfree.chart.entity.EntityCollection) Iterator(java.util.Iterator) ChartEntity(org.jfree.chart.entity.ChartEntity) StandardURLTagFragmentGenerator(org.jfree.chart.imagemap.StandardURLTagFragmentGenerator) Map(java.util.Map) GradientPaint(java.awt.GradientPaint)

Example 7 with ChartEntity

use of org.jfree.chart.entity.ChartEntity in project adempiere by adempiere.

the class Graph method getGraphColumn.

//	setY_TargetLabel
/**
	 * Get BarGraphColumn for ChartEntity
	 * @param event
	 * @return BarGraphColumn or null if not found
	 */
private GraphColumn getGraphColumn(ChartMouseEvent event) {
    ChartEntity entity = event.getEntity();
    String key = null;
    if (entity instanceof CategoryItemEntity) {
        Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey();
        if (colKey != null) {
            key = colKey.toString();
        }
    } else if (entity instanceof PieSectionEntity) {
        Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
        if (sectionKey != null) {
            key = sectionKey.toString();
        }
    }
    if (key == null) {
        return null;
    }
    for (int i = 0; i < list.size(); i++) {
        final String label = list.get(i).getLabel();
        if (key.equals(label)) {
            return list.get(i);
        }
    }
    //
    return null;
}
Also used : ChartEntity(org.jfree.chart.entity.ChartEntity) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity) Point(java.awt.Point)

Aggregations

ChartEntity (org.jfree.chart.entity.ChartEntity)7 PieSectionEntity (org.jfree.chart.entity.PieSectionEntity)6 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)4 Point (java.awt.Point)2 BufferedImage (java.awt.image.BufferedImage)2 Account (jgnash.engine.Account)2 RootAccount (jgnash.engine.RootAccount)2 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)2 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)2 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)2 XYItemEntity (org.jfree.chart.entity.XYItemEntity)2 TimeSeries (org.jfree.data.time.TimeSeries)2 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)2 TimeSeriesDataItem (org.jfree.data.time.TimeSeriesDataItem)2 AImage (org.zkoss.image.AImage)2 Event (org.zkoss.zk.ui.event.Event)2 EventListener (org.zkoss.zk.ui.event.EventListener)2 MouseEvent (org.zkoss.zk.ui.event.MouseEvent)2 Area (org.zkoss.zul.Area)2 Imagemap (org.zkoss.zul.Imagemap)2