Example usage for org.jfree.chart ChartRenderingInfo getEntityCollection

List of usage examples for org.jfree.chart ChartRenderingInfo getEntityCollection

Introduction

In this page you can find the example usage for org.jfree.chart ChartRenderingInfo getEntityCollection.

Prototype

public EntityCollection getEntityCollection() 

Source Link

Document

Returns the collection of entities maintained by this instance.

Usage

From source file:org.n52.server.sos.generator.EESGenerator.java

@Override
public RepresentationResponse producePresentation(DesignOptions options) throws Exception {
    ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
    String chartUrl = createChart(options, renderingInfo);

    Rectangle2D plotArea = renderingInfo.getPlotInfo().getDataArea();
    for (Axis axis : renderer.getAxisMapping().values()) {
        axis.setMaxY(plotArea.getMaxY());
        axis.setMinY(plotArea.getMinY());
    }//from  w ww  .j  a  v  a2s .  c  o m

    ImageEntity[] entities = {};
    if (!this.isOverview) {
        LOGGER.debug("Produced EES diagram " + chartUrl);
        entities = createImageEntities(renderingInfo.getEntityCollection());
    } else {
        LOGGER.debug("Produced EES Overview diagram " + chartUrl);
    }

    Bounds chartArea = new Bounds(plotArea.getMinX(), plotArea.getMaxX(), plotArea.getMinY(),
            plotArea.getMaxY());
    return new EESDataResponse(chartUrl, options, chartArea, entities, renderer.getAxisMapping());
}

From source file:org.n52.server.io.EESGenerator.java

@Override
public RepresentationResponse producePresentation(DesignOptions options) throws GeneratorException {
    ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
    String chartUrl = createChart(options, renderingInfo);

    Rectangle2D plotArea = renderingInfo.getPlotInfo().getDataArea();
    for (Axis axis : renderer.getAxisMapping().values()) {
        axis.setMaxY(plotArea.getMaxY());
        axis.setMinY(plotArea.getMinY());
    }//from www  . j  a  v  a 2 s . c  o m

    ImageEntity[] entities = {};
    if (!this.isOverview) {
        LOGGER.debug("Produced EES diagram " + chartUrl);
        entities = createImageEntities(renderingInfo.getEntityCollection());
    } else {
        LOGGER.debug("Produced EES Overview diagram " + chartUrl);
    }

    Bounds chartArea = new Bounds(plotArea.getMinX(), plotArea.getMaxX(), plotArea.getMinY(),
            plotArea.getMaxY());
    return new EESDataResponse(chartUrl, options, chartArea, entities, renderer.getAxisMapping());
}

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);/*  ww w  .j a  va2  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.editor.WChartEditor.java

private void render(JFreeChart chart) {
    ChartRenderingInfo info = new ChartRenderingInfo();
    int width = 400;
    int height = chartModel.getWinHeight();
    BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
    try {//  ww  w.  j a  v a2 s  . c o  m
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

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

        Panel panel = getComponent();
        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;
            String seriesName = null;
            if (entity instanceof CategoryItemEntity) {
                CategoryItemEntity item = ((CategoryItemEntity) entity);
                Comparable<?> colKey = item.getColumnKey();
                Comparable<?> rowKey = item.getRowKey();
                if (colKey != null && rowKey != null) {
                    key = colKey.toString();
                    seriesName = rowKey.toString();
                }
            } else if (entity instanceof PieSectionEntity) {
                Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
                if (sectionKey != null) {
                    key = sectionKey.toString();
                }
            }
            if (entity instanceof XYItemEntity) {
                XYItemEntity item = ((XYItemEntity) entity);
                if (item.getDataset() instanceof TimeSeriesCollection) {
                    TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
                    TimeSeries series = data.getSeries(item.getSeriesIndex());
                    TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
                    seriesName = series.getKey().toString();
                    key = dataitem.getPeriod().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__" + seriesName + "__" + 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) {
                    String[] strs = areaId.split("__");
                    if (strs.length == 3) {
                        chartMouseClicked(strs[2], strs[1]);
                    }
                }
            }
        });
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }

}

From source file:probe.com.view.core.chart4j.VennDiagramPanel.java

/**
 * Returns a list of the entities at the given x, y view location.
 *
 * @param viewX the x location/*from w  w w .jav  a  2 s . co m*/
 * @param viewY the y location
 * @return a list of the entities
 */
public ArrayList<ChartEntity> getEntitiesForPoint(int viewX, int viewY) {

    ArrayList<ChartEntity> entitiesForPoint = new ArrayList<ChartEntity>();
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();

    if (info != null) {
        Insets insets = chartPanel.getInsets();
        double x = (viewX - insets.left) / chartPanel.getScaleX();
        double y = (viewY - insets.top) / chartPanel.getScaleY();
        EntityCollection allEntities = info.getEntityCollection();
        int numEntities = allEntities.getEntityCount();

        for (int i = 0; i < numEntities; i++) {
            ChartEntity entity = allEntities.getEntity(i);
            if (entity.getArea().contains(x, y)) {
                entitiesForPoint.add(entity);
            }
        }
    }

    return entitiesForPoint;
}

From source file:com.igalia.java.zk.components.JFreeChartEngine.java

public byte[] drawChart(Object data) {
    Chart chart = (Chart) data;//  ww  w.  j a  va 2  s. c  o  m
    ChartImpl impl = getChartImpl(chart);
    JFreeChart jfchart = impl.createChart(chart);

    Plot plot = (Plot) jfchart.getPlot();
    float alpha = (float) (((float) chart.getFgAlpha()) / 255);
    plot.setForegroundAlpha(alpha);

    alpha = (float) (((float) chart.getBgAlpha()) / 255);
    plot.setBackgroundAlpha(alpha);

    int[] bgRGB = chart.getBgRGB();
    if (bgRGB != null) {
        plot.setBackgroundPaint(new Color(bgRGB[0], bgRGB[1], bgRGB[2], chart.getBgAlpha()));
    }

    int[] paneRGB = chart.getPaneRGB();
    if (paneRGB != null) {
        jfchart.setBackgroundPaint(new Color(paneRGB[0], paneRGB[1], paneRGB[2], chart.getPaneAlpha()));
    }

    //since 3.6.3, JFreeChart 1.0.13 change default fonts which does not support Chinese, allow
    //developer to set font.

    //title font
    final Font tfont = chart.getTitleFont();
    if (tfont != null) {
        jfchart.getTitle().setFont(tfont);
    }

    //legend font
    final Font lfont = chart.getLegendFont();
    if (lfont != null) {
        jfchart.getLegend().setItemFont(lfont);
    }

    if (plot instanceof CategoryPlot) {
        final CategoryPlot cplot = (CategoryPlot) plot;
        cplot.setRangeGridlinePaint(new Color(0xc0, 0xc0, 0xc0));

        //Domain axis(x axis)
        final Font xlbfont = chart.getXAxisFont();
        final Font xtkfont = chart.getXAxisTickFont();
        if (xlbfont != null) {
            cplot.getDomainAxis().setLabelFont(xlbfont);
        }
        if (xtkfont != null) {
            cplot.getDomainAxis().setTickLabelFont(xtkfont);
        }

        Color[] colorMappings = (Color[]) chart.getAttribute("series-color-mappings");
        if (colorMappings != null) {
            for (int ii = 0; ii < colorMappings.length; ii++) {
                cplot.getRenderer().setSeriesPaint(ii, colorMappings[ii]);
            }
        }

        Double lowerBound = (Double) chart.getAttribute("range-axis-lower-bound");
        if (lowerBound != null) {
            cplot.getRangeAxis().setAutoRange(false);
            cplot.getRangeAxis().setLowerBound(lowerBound);
        }

        Double upperBound = (Double) chart.getAttribute("range-axis-upper-bound");
        if (upperBound != null) {
            cplot.getRangeAxis().setAutoRange(false);
            cplot.getRangeAxis().setUpperBound(upperBound);
        }

        //Range axis(y axis)
        final Font ylbfont = chart.getYAxisFont();
        final Font ytkfont = chart.getYAxisTickFont();
        if (ylbfont != null) {
            cplot.getRangeAxis().setLabelFont(ylbfont);
        }
        if (ytkfont != null) {
            cplot.getRangeAxis().setTickLabelFont(ytkfont);
        }
    } else if (plot instanceof XYPlot) {
        final XYPlot xyplot = (XYPlot) plot;
        xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        //Domain axis(x axis)
        final Font xlbfont = chart.getXAxisFont();
        final Font xtkfont = chart.getXAxisTickFont();
        if (xlbfont != null) {
            xyplot.getDomainAxis().setLabelFont(xlbfont);
        }
        if (xtkfont != null) {
            xyplot.getDomainAxis().setTickLabelFont(xtkfont);
        }

        //Range axis(y axis)
        final Font ylbfont = chart.getYAxisFont();
        final Font ytkfont = chart.getYAxisTickFont();
        if (ylbfont != null) {
            xyplot.getRangeAxis().setLabelFont(ylbfont);
        }
        if (ytkfont != null) {
            xyplot.getRangeAxis().setTickLabelFont(ytkfont);
        }
    } else if (plot instanceof PiePlot) {
        plot.setOutlineStroke(null);
    }

    //callbacks for each area
    ChartRenderingInfo jfinfo = new ChartRenderingInfo();
    BufferedImage bi = jfchart.createBufferedImage(chart.getIntWidth(), chart.getIntHeight(),
            Transparency.TRANSLUCENT, jfinfo);

    //remove old areas
    if (chart.getChildren().size() > 20)
        chart.invalidate(); //improve performance if too many chart
    chart.getChildren().clear();

    if (Events.isListened(chart, Events.ON_CLICK, false) || chart.isShowTooltiptext()) {
        int j = 0;
        String preUrl = null;
        for (Iterator it = jfinfo.getEntityCollection().iterator(); it.hasNext();) {
            ChartEntity ce = (ChartEntity) it.next();
            final String url = ce.getURLText();

            //workaround JFreeChart's bug (skip replicate areas)
            if (url != null) {
                if (preUrl == null) {
                    preUrl = url;
                } else if (url.equals(preUrl)) { //start replicate, skip
                    break;
                }
            }

            //1. JFreeChartEntity area cover the whole chart, will "mask" other areas
            //2. LegendTitle area cover the whole legend, will "mask" each legend
            //3. PlotEntity cover the whole chart plotting araa, will "mask" each bar/line/area
            if (!(ce instanceof JFreeChartEntity)
                    && !(ce instanceof TitleEntity && ((TitleEntity) ce).getTitle() instanceof LegendTitle)
                    && !(ce instanceof PlotEntity)) {
                Area area = new Area();
                area.setParent(chart);
                area.setCoords(ce.getShapeCoords());
                area.setShape(ce.getShapeType());
                area.setId("area_" + chart.getId() + '_' + (j++));
                if (chart.isShowTooltiptext() && ce.getToolTipText() != null) {
                    area.setTooltiptext(ce.getToolTipText());
                }
                area.setAttribute("url", ce.getURLText());
                impl.render(chart, area, ce);
                if (chart.getAreaListener() != null) {
                    try {
                        chart.getAreaListener().onRender(area, ce);
                    } catch (Exception ex) {
                        throw UiException.Aide.wrap(ex);
                    }
                }
            }
        }
    }
    //clean up the "LEGEND_SEQ"
    //used for workaround LegendItemEntity.getSeries() always return 0
    //used for workaround TickLabelEntity no information
    chart.removeAttribute("LEGEND_SEQ");
    chart.removeAttribute("TICK_SEQ");

    try {
        //encode into png image format byte array
        return EncoderUtil.encode(bi, ImageFormat.PNG, true);
    } catch (java.io.IOException ex) {
        throw UiException.Aide.wrap(ex);
    }
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

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());

        // Next: most of our chart entities will not have URLs. URL values
        // don't inherit in the imagemap, so if we want the entire image
        // to have a single URL, we need to assign that URL to every
        // area in the chart.
        for (Iterator i = entities.iterator(); i.hasNext();) {
            ChartEntity ce = (ChartEntity) i.next();
            // check for no-op chart entity - these won't appear in the
            // 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);//from   w  w w .j av a  2s .  c o m
        }

        // 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 + '"');

    // imagemaps have hyperlink borders by default, even if we don't
    // have a URL we're pointing to.  Turn that border off.
    if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
        out.write(" border=\"0\"");

    // Our client might want to add attributes to the image tag. Look
    // through the query parameters we received for arbitrary attributes
    // 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();
}

From source file:com.tonbeller.jpivot.chart.ChartComponent.java

/**
 * Writes an image map as a String/*from w  ww .j  a  v a 2 s  .  c o m*/
 * This function has been requested to be added to jfreechart
 * Also requires slight change to ChartEntity.getImageMapAreaTag()
 * to produce valid xml tag and use &amp; entity in urls.
 * Diffs sent to jfreechart project - so hopefully this will be in there soon
 *
 * @param name  the map name.
 * @param info  the chart rendering info.
 * @param useOverLibForToolTips  whether to use OverLIB for tooltips
 *                               (http://www.bosrup.com/web/overlib/).
 */
public String writeImageMap(String name, ChartRenderingInfo info, boolean useOverLibForToolTips) {
    StringBuffer sb = new StringBuffer();
    sb.append("<map name=\"" + name + "\">");
    EntityCollection entities = info.getEntityCollection();
    Iterator iterator = entities.iterator();

    while (iterator.hasNext()) {
        ChartEntity entity = (ChartEntity) iterator.next();
        // the tag returned by getImageMapAreaTag is not valid xml
        //String area = entity.getImageMapAreaTag(useOverLibForToolTips);

        String area = "";

        if (useOverLibForToolTips)
            area = entity.getImageMapAreaTag(new org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator(),
                    new org.jfree.chart.imagemap.StandardURLTagFragmentGenerator());
        else
            area = entity.getImageMapAreaTag(new org.jfree.chart.imagemap.StandardToolTipTagFragmentGenerator(),
                    new org.jfree.chart.imagemap.StandardURLTagFragmentGenerator());
        // modify to valid xml tag
        area = area.replaceAll("&", "&amp;");
        //area = area.toLowerCase();
        //area = area.replaceAll(">$", "/>");
        if (area.length() > 0) {
            sb.append(area);
        }
    }
    sb.append("</map>");
    return sb.toString();
}

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  va2  s.  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("},");
        }//w ww. j  av  a 2 s  .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());
    }
}