List of usage examples for org.jfree.chart.entity ChartEntity getToolTipText
public String getToolTipText()
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Returns a string for the tooltip./*from ww w. java2 s . co m*/ * * @param e the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(org.eclipse.swt.events.MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Rectangle insets = getClientArea(); ChartEntity entity = entities.getEntity((int) ((e.x - insets.x) / this.scaleX), (int) ((e.y - insets.y) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:com.igalia.java.zk.components.JFreeChartEngine.java
public byte[] drawChart(Object data) { Chart chart = (Chart) data;//from w w w . j a va 2 s .co 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:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Returns a string for the tooltip.// ww w.java 2 s .c om * * @param e * the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(final org.eclipse.swt.events.MouseEvent e) { String result = null; if (this.info != null) { final EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { final Rectangle insets = getClientArea(); final ChartEntity entity = entities.getEntity((int) ((e.x - insets.x) / this.scaleX), (int) ((e.y - insets.y) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
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 va2 s . com*/ 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:com.isti.traceview.common.TraceViewChartPanel.java
/** * Returns a string for the tooltip.// www . j a va 2s . com * * @param e * the mouse event. * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX), (int) ((e.getY() - insets.top) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Returns a string for the tooltip./*from w ww. j a v a2 s . co m*/ * * @param e the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX), (int) ((e.getY() - insets.top) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Returns a string for the tooltip.//from w ww.j a v a 2 s .c o m * * @param e * the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ @Override public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX), (int) ((e.getY() - insets.top) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }