Example usage for org.jfree.chart.entity ChartEntity getShapeType

List of usage examples for org.jfree.chart.entity ChartEntity getShapeType

Introduction

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

Prototype

public String getShapeType() 

Source Link

Document

Returns a string describing the entity area.

Usage

From source file:net.sf.jasperreports.charts.util.ChartUtil.java

private static JRPrintImageArea getImageArea(ChartEntity entity) {
    JRPrintImageArea area = new JRPrintImageArea();
    area.setShape(JRPrintImageArea.getShape(entity.getShapeType()));

    int[] coordinates = getCoordinates(entity);
    if (coordinates != null) {
        area.setCoordinates(coordinates);
    }//  w  w  w .j ava 2s.c o  m
    return area;
}

From source file:com.swordlord.gozer.components.wicket.graph.common.GWChartPanel.java

protected DynamicImageMap constructImageMap(ChartImage image, String mapName) {
    DynamicImageMap imageMap = new DynamicImageMap("imageMap", mapName);
    EntityCollection entities = image.getRenderingInfo().getEntityCollection();
    if (entities != null) {
        int count = entities.getEntityCount();
        for (int i = count - 1; i >= 0; i--) {
            final ChartEntity entity = entities.getEntity(i);
            imageMap.addArea(entity.getShapeType(), entity.getShapeCoords(), entity.getToolTipText(),
                    new AjaxLink<Object>("link") {
                        private static final long serialVersionUID = -7982198051678987986L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            onClickCallback(target, entity);
                        }//from  www. j ava 2  s  .c  o m
                    });
        }
    }
    return imageMap;
}

From source file:com.manydesigns.portofino.pageactions.chart.jfreechart.JFreeChartInstance.java

public void toXhtml(@NotNull XhtmlBuffer xb) {
    xb.openElement("img");
    xb.addAttribute("src", chartUrl);
    xb.addAttribute("alt", alt);
    xb.addAttribute("usemap", "#" + mapId);
    xb.addAttribute("style", "border: none;");
    xb.addAttribute("class", "img-responsive");
    xb.closeElement("img");

    xb.openElement("map");
    xb.addAttribute("id", mapId);
    xb.addAttribute("name", mapId);
    Iterator iter = renderingInfo.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity ce = (ChartEntity) iter.next();
        String shapeType = ce.getShapeType();
        String shapeCoords = ce.getShapeCoords();
        String tooltipText = ce.getToolTipText();
        String urltext = ce.getURLText();

        if (urltext == null)
            continue;

        xb.openElement("area");
        xb.addAttribute("shape", shapeType);
        xb.addAttribute("coords", shapeCoords);
        xb.addAttribute("title", tooltipText);
        xb.addAttribute("alt", tooltipText);
        xb.addAttribute("href", urltext);
        xb.closeElement("area");
    }// w w w  .  j  a v  a 2  s. c  o  m
    xb.closeElement("map");
}

From source file:org.openfaces.component.chart.impl.helpers.MapRenderUtilities.java

private static String getTitleImageMapAreaTag(Chart chart,
        ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
        URLTagFragmentGenerator urlTagFragmentGenerator, ChartEntity entity) {
    StringBuilder tag = new StringBuilder();
    ChartTitle title = chart.getTitle();
    if (title == null)
        return "";
    boolean hasURL = entity.getURLText() != null && !entity.getURLText().equals("");
    boolean hasAction = title.getActionExpression() != null || title.getActionListeners().length > 0;
    boolean hasToolTip = title.getTooltip() != null && !title.getTooltip().equals("");

    if (!hasURL && !hasToolTip && !hasAction)
        return "";

    String fieldId = chart.getClientId(FacesContext.getCurrentInstance()) + ACTION_FIELD_SUFFIX;

    tag.append("<area");

    if (hasAction)
        tag.append(" onclick=\"O$.setValue('").append(fieldId).append("','title'); O$.submitById('")
                .append(fieldId).append("');\"");

    tag.append(" shape=\"").append(entity.getShapeType()).append("\"" + " coords=\"")
            .append(entity.getShapeCoords()).append("\"");

    if (hasToolTip) {
        String toolTipText = entity.getToolTipText();
        if (toolTipText != null)
            tag.append(toolTipTagFragmentGenerator.generateToolTipFragment(toolTipText));
    }// w  w  w  .  j  a v a  2  s  . c  o m

    if (hasURL && !hasAction)
        tag.append(urlTagFragmentGenerator.generateURLFragment(entity.getURLText()));

    if (!hasToolTip)
        tag.append(" alt=\"\"");

    tag.append("/>");
    return tag.toString();
}

From source file:com.manydesigns.portofino.pageactions.chart.JFreeChartInstance.java

public void toXhtml(@NotNull XhtmlBuffer xb) {
    xb.openElement("img");
    xb.addAttribute("src", chartUrl);
    xb.addAttribute("alt", alt);
    xb.addAttribute("usemap", "#" + mapId);
    xb.addAttribute("style", "border: none;");
    xb.closeElement("img");

    xb.openElement("map");
    xb.addAttribute("id", mapId);
    xb.addAttribute("name", mapId);
    Iterator iter = renderingInfo.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity ce = (ChartEntity) iter.next();
        String shapeType = ce.getShapeType();
        String shapeCoords = ce.getShapeCoords();
        String tooltipText = ce.getToolTipText();
        String urltext = ce.getURLText();

        if (urltext == null)
            continue;

        xb.openElement("area");
        xb.addAttribute("shape", shapeType);
        xb.addAttribute("coords", shapeCoords);
        xb.addAttribute("title", tooltipText);
        xb.addAttribute("alt", tooltipText);
        xb.addAttribute("href", urltext);
        //hongliangpan add
        xb.addAttribute("target", "_BLANK");
        // xb.addAttribute("onclick",
        // "window.open(this.href, '_blank', 'scrollbars=0,resizable=0;width=300');return false");

        xb.closeElement("area");
    }//from  w  w w.j av  a2s . c  o  m
    xb.closeElement("map");
}

From source file:de.laures.cewolf.taglib.tags.ChartMapTag.java

public int doStartTag() throws JspException {
    // Object linkGenerator = getLinkGenerator();
    Mapped root = (Mapped) PageUtils.findRoot(this, pageContext);
    root.enableMapping();/*from www.  j  a  va  2s .c o  m*/
    String chartId = ((CewolfRootTag) root).getChartId();
    try {
        Dataset dataset = PageUtils.getDataset(chartId, pageContext);
        Writer out = pageContext.getOut();
        final boolean isIE = BrowserDetection.isIE((HttpServletRequest) pageContext.getRequest());
        if (hasToolTips()) {
            enableToolTips(out, isIE);
        }
        out.write("<MAP name=\"" + chartId + "\">\n");
        ChartRenderingInfo info = (ChartRenderingInfo) root.getRenderingInfo();
        Iterator entities = info.getEntityCollection().iterator();
        while (entities.hasNext()) {
            ChartEntity ce = (ChartEntity) entities.next();
            out.write("\n<AREA shape=\"" + ce.getShapeType() + "\" ");
            out.write("COORDS=\"" + ce.getShapeCoords() + "\" ");
            if (ce instanceof XYItemEntity) {
                dataset = ((XYItemEntity) ce).getDataset();
            }
            if (!(ce instanceof LegendItemEntity)) {
                if (hasToolTips()) {
                    writeOutToolTip(dataset, out, isIE, ce);
                }
                if (hasLinks()) {
                    writeOutLink(linkGenerator, dataset, out, ce);
                }
            }
            out.write(">");
        }
    } catch (IOException ioex) {
        log.error(ioex);
        throw new JspException(ioex.getMessage());
    } catch (CewolfException cwex) {
        log.error(cwex);
        throw new JspException(cwex.getMessage());
    }
    return EVAL_PAGE;
}

From source file:org.orbeon.oxf.processor.JFreeChartProcessor.java

public ProcessorOutput createOutput(String name) {
    return new ProcessorOutputImpl(JFreeChartProcessor.this, name) {
        public void readImpl(PipelineContext context, XMLReceiver xmlReceiver) {
            JFreeChartSerializer.ChartConfig chartConfig = readChartConfig(context);
            ChartInfo info = createChart(context, chartConfig);
            try {
                xmlReceiver.startDocument();
                xmlReceiver.startElement("", "chart-info", "chart-info", new AttributesImpl());

                xmlReceiver.startElement("", "file", "file", new AttributesImpl());
                xmlReceiver.characters(info.file.toCharArray(), 0, info.file.length());
                xmlReceiver.endElement("", "file", "file");

                if (chartConfig.getMap() != null) {
                    AttributesImpl atts = new AttributesImpl();

                    atts.addAttribute("", "name", "name", "CDATA", chartConfig.getMap());
                    xmlReceiver.startElement("", "map", "map", atts);

                    EntityCollection entities = info.getInfo().getEntityCollection();

                    Iterator iterator = entities.iterator();
                    while (iterator.hasNext()) {
                        ChartEntity entity = (ChartEntity) iterator.next();
                        AttributesImpl attr = new AttributesImpl();
                        attr.addAttribute("", "shape", "shape", "CDATA", entity.getShapeType());
                        attr.addAttribute("", "coords", "coords", "CDATA", entity.getShapeCoords());

                        if (entity.getURLText() != null && !entity.getURLText().equals("")) {
                            attr.addAttribute("", "href", "href", "CDATA", entity.getURLText());
                        }/*from ww w .ja  va2  s.c o  m*/
                        if (entity.getToolTipText() != null && !entity.getToolTipText().equals("")) {
                            attr.addAttribute("", "title", "title", "CDATA", entity.getToolTipText());

                        }
                        xmlReceiver.startElement("", "area", "area", attr);
                        xmlReceiver.endElement("", "area", "area");
                    }

                    xmlReceiver.endElement("", "map", "map");
                }
                xmlReceiver.endElement("", "chart-info", "chart-info");
                xmlReceiver.endDocument();

            } catch (SAXException e) {
                throw new OXFException(e);
            }
        }
    };
}

From source file:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java

@Override
public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight,
        final GoalModel goalModel) {
    GraphBuilder builder = new GraphBuilder();
    builder.setMGoal(goalModel.goal);//from  www .j  a v a  2 s. com
    builder.setXAxisLabel(goalModel.xAxisLabel);
    builder.setYAxisLabel(goalModel.yAxisLabel);
    builder.loadDataSet(goalModel.columnList);
    JFreeChart chart = builder.createChart(goalModel.chartType);
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.getPlot().setForegroundAlpha(0.6f);
    if (goalModel.zoomFactor > 0) {
        chartWidth = chartWidth * goalModel.zoomFactor / 100;
        chartHeight = chartHeight * goalModel.zoomFactor / 100;
    }
    if (!goalModel.showTitle) {
        chart.setTitle("");
    }
    BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, info);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();

        myImage.setContent(image);
        parent.appendChild(myImage);

        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) {
            ChartEntity entity = (ChartEntity) it.next();

            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) {
                continue;
            }

            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG_" + key);
            count++;
        }

        myImage.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    List<GraphColumn> list = goalModel.columnList;
                    for (int i = 0; i < list.size(); i++) {
                        String s = "_WG_" + list.get(i).getLabel();
                        if (areaId.endsWith(s)) {
                            chartMouseClicked(goalModel.goal, list.get(i));
                            return;
                        }
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
        return false;
    }
    return true;
}

From source file:org.adempiere.webui.apps.graph.WGraph.java

private void render(JFreeChart chart) {
    ChartRenderingInfo info = new ChartRenderingInfo();
    int width = 560;
    int height = 400;
    if (zoomFactor > 0) {
        width = width * zoomFactor / 100;
        height = height * zoomFactor / 100;
    }//from  www.j a v a2s . com
    if (m_hideTitle) {
        chart.setTitle("");
    }
    BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage image = new AImage("", bytes);
        Imagemap myImage = new Imagemap();

        myImage.setContent(image);
        if (panel.getPanelchildren() != null) {
            panel.getPanelchildren().getChildren().clear();
            panel.getPanelchildren().appendChild(myImage);
        } else {
            Panelchildren pc = new Panelchildren();
            panel.appendChild(pc);
            pc.appendChild(myImage);
        }

        int count = 0;
        for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) {
            ChartEntity entity = (ChartEntity) it.next();

            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) {
                continue;
            }

            Area area = new Area();
            myImage.appendChild(area);
            area.setCoords(entity.getShapeCoords());
            area.setShape(entity.getShapeType());
            area.setTooltiptext(entity.getToolTipText());
            area.setId(count + "_WG_" + key);
            count++;
        }

        myImage.addEventListener(Events.ON_CLICK, new EventListener() {
            public void onEvent(Event event) throws Exception {
                MouseEvent me = (MouseEvent) event;
                String areaId = me.getArea();
                if (areaId != null) {
                    for (int i = 0; i < list.size(); i++) {
                        String s = "_WG_" + list.get(i).getLabel();
                        if (areaId.endsWith(s)) {
                            chartMouseClicked(i);
                            return;
                        }
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private void encodeItemTips(FacesContext context, UIChart comp, ChartRenderingInfo info) throws IOException {
    StringBuilder buf = new StringBuilder();

    buf.append("Ext.om.AreaTips.init();\n");
    buf.append("Ext.om.AreaTips.register({");
    buf.append("target:'").append(comp.getClientId(context)).append("'");
    buf.append(",trackMouse:true");
    buf.append(",areas:[");

    EntityCollection entities = info.getEntityCollection();
    Iterator it = entities.iterator();
    while (it.hasNext()) {
        ChartEntity entity = (ChartEntity) it.next();
        String tooltip = entity.getToolTipText();
        if (tooltip != null) {
            buf.append("{");
            buf.append("shape:'").append(entity.getShapeType()).append("'");
            buf.append(",coords:[").append(entity.getShapeCoords()).append("]");
            buf.append(",text:").append(HtmlEncoder.enquote(tooltip));
            buf.append("},");
        }/*  ww w . j a v  a  2s.c o m*/
    }

    if (buf.charAt(buf.length() - 1) == ',') {
        buf.setLength(buf.length() - 1);
    }

    buf.append("]});\n");

    ResourceManager rm = ResourceManager.getInstance(context);
    if (isAjaxResponse(context)) {
        AjaxResponseWriter out = (AjaxResponseWriter) context.getResponseWriter();
        out.writeScript("OM.ajax.loadScript('" + rm.getResourceURL("/ext/om/AreaTips.js") + "');\n");
        out.writeScript(buf.toString());
    } else {
        YuiExtResource resource = YuiExtResource.register(rm, "Ext.om.AreaTips");
        resource.addInitScript(buf.toString());
    }
}