List of usage examples for java.lang Comparable toString
public String toString()
From source file:ch.unibe.iam.scg.archie.model.ProviderChartFactory.java
/** * @param dataset/*w ww . ja v a 2s . c om*/ * @return */ private DefaultCategoryDataset createJFreeBarDataset(DataSet dataset) { DefaultCategoryDataset categoryDataSet = new DefaultCategoryDataset(); int[] rows = this.model.getRows(); int[] columns = this.model.getColumns(); int rowTitleColumnIndex = this.model.getRowTitleColumnIndex(); for (int i = 0; i < rows.length; i++) { int rowIndex = rows[i]; Comparable<?>[] row = dataset.getRow(rowIndex); String rowTitle = row[rowTitleColumnIndex].toString(); for (int j = 0; j < columns.length; j++) { double value = 0.0; int columnIndex = columns[j]; String columnTitle = (String) dataset.getHeadings().get(columnIndex); Comparable<?> cell = dataset.getCell(rowIndex, columnIndex); if (cell instanceof Money) { value = ((Money) cell).doubleValue(); } else { value = new Double(cell.toString()); } categoryDataSet.addValue(value, columnTitle, rowTitle); } } return categoryDataSet; }
From source file:org.jfree.data.KeyedObjects.java
/** * Removes a value from the collection./*from www.j ava 2s . c o m*/ * * @param key the key (<code>null</code> not permitted). * * @see #removeValue(int) * * @throws UnknownKeyException if the key is not recognised. */ public void removeValue(Comparable key) { // defer argument checking int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key.toString() + ") is not recognised."); } removeValue(index); }
From source file:com.itemanalysis.jmetrik.graph.barchart.BarChartPanel.java
public void updateDataset(TwoWayTable table) { String groupingName = ""; try {/*from w w w.j a v a 2 s . c o m*/ boolean showFreq = command.getSelectOneOption("yaxis").isValueSelected("freq"); if (command.getFreeOption("groupvar").hasValue()) { groupingName = command.getFreeOption("groupvar").getString(); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Iterator<Comparable<?>> rowIter = table.rowValuesIterator(); Iterator<Comparable<?>> colIter = null; Comparable<?> r = null; Comparable<?> c = null; while (rowIter.hasNext()) { r = rowIter.next(); colIter = table.colValuesIterator(); while (colIter.hasNext()) { c = colIter.next(); if (showFreq) { dataset.addValue(table.getCount(r, c), r.toString(), c.toString()); } else { dataset.addValue(table.getCount(r, c) / table.getFreqSum(), (groupingName + " " + r.toString()), c.toString()); } } } CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDataset(dataset); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }
From source file:org.pentaho.platform.uifoundation.chart.XYSeriesCollectionChartComponent.java
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); String contextPath = requestContext.getContextPath(); setXslProperty("baseUrl", contextPath + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$ definitionPath);/*from w w w . j av a 2 s .c o m*/ errorElement.addElement("message").setText(message); //$NON-NLS-1$ error(message); return result; } // create a pie definition from the XML definition dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); //$NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; //$NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$ } if (height == -1) { height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$ } } catch (Exception e) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$ .getText(); } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$ } Element root = result.addElement("charts"); //$NON-NLS-1$ XYSeriesCollection chartDataDefinition = (XYSeriesCollection) dataDefinition; if (chartDataDefinition.getSeriesCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); //$NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$ for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) { for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) { Number value = chartDataDefinition.getY(row, column); Comparable rowKey = chartDataDefinition.getSeriesKey(row); Number columnKey = chartDataDefinition.getX(row, column); Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$ valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$ valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$ valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$ } } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$ chartElement.addElement("image").setText(fileName); //$NON-NLS-1$ } return result; }
From source file:org.pentaho.platform.uifoundation.chart.XYZSeriesCollectionChartComponent.java
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$ PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$ definitionPath);//w ww . j a va 2 s . c o m errorElement.addElement("message").setText(message); //$NON-NLS-1$ error(message); return result; } // create a pie definition from the XML definition dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); //$NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; //$NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$ } if (height == -1) { height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$ } } catch (Exception e) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$ .getText(); } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$ } Element root = result.addElement("charts"); //$NON-NLS-1$ XYZSeriesCollectionChartDefinition chartDataDefinition = (XYZSeriesCollectionChartDefinition) dataDefinition; if (chartDataDefinition.getSeriesCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); //$NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$ for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) { for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) { Number value = chartDataDefinition.getY(row, column); Comparable rowKey = chartDataDefinition.getSeriesKey(row); Number columnKey = chartDataDefinition.getX(row, column); Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$ valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$ valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$ valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$ } } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$ chartElement.addElement("image").setText(fileName); //$NON-NLS-1$ } return result; }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override public void getModelCoordinatesInfo(final int xOnScreen, final int yOnScreen, final IDisplaySurface g, final Point positionInPixels, final StringBuilder sb) { final int x = xOnScreen - positionInPixels.x; final int y = yOnScreen - positionInPixels.y; final ChartEntity entity = info.getEntityCollection().getEntity(x, y); // getChart().handleClick(x, y, info); if (entity instanceof XYItemEntity) { final XYDataset data = ((XYItemEntity) entity).getDataset(); final int index = ((XYItemEntity) entity).getItem(); final int series = ((XYItemEntity) entity).getSeriesIndex(); final double xx = data.getXValue(series, index); final double yy = data.getYValue(series, index); final XYPlot plot = (XYPlot) getJFChart().getPlot(); final ValueAxis xAxis = plot.getDomainAxis(series); final ValueAxis yAxis = plot.getRangeAxis(series); final boolean xInt = xx % 1 == 0; final boolean yInt = yy % 1 == 0; String xTitle = xAxis.getLabel(); if (StringUtils.isBlank(xTitle)) { xTitle = "X"; }/*from w w w . j a v a2 s.co m*/ String yTitle = yAxis.getLabel(); if (StringUtils.isBlank(yTitle)) { yTitle = "Y"; } sb.append(xTitle).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); sb.append(" | ").append(yTitle).append(" ").append(yInt ? (int) yy : String.format("%.2f", yy)); return; } else if (entity instanceof PieSectionEntity) { final String title = ((PieSectionEntity) entity).getSectionKey().toString(); final PieDataset data = ((PieSectionEntity) entity).getDataset(); final int index = ((PieSectionEntity) entity).getSectionIndex(); final double xx = data.getValue(index).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); return; } else if (entity instanceof CategoryItemEntity) { final Comparable<?> columnKey = ((CategoryItemEntity) entity).getColumnKey(); final String title = columnKey.toString(); final CategoryDataset data = ((CategoryItemEntity) entity).getDataset(); final Comparable<?> rowKey = ((CategoryItemEntity) entity).getRowKey(); final double xx = data.getValue(rowKey, columnKey).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); return; } }
From source file:com.diversityarrays.kdxplore.trials.PlotCellRenderer.java
private String collectCellHtml(boolean isSelected, Plot plot, StringBuilder sb, Map<TraitInstance, Comparable<?>> tempMap) { String tttResult = null;//from w w w . j a v a 2 s . c om String sep = "<hr>"; Trial trial = curationData.getTrial(); Date trialPlantingDate = trial.getTrialPlantingDate(); TraitNameStyle traitNameStyle = trial.getTraitNameStyle(); for (Integer traitId : traitInstancesByTraitId.keySet()) { Trait trait = traitById.get(traitId); for (TraitInstance instance : traitInstancesByTraitId.get(traitId)) { if (instance == activeInstance) { CurationCellValue ccv = curationTableModel .getCurationCellValueForTraitInstanceInPlot(activeInstance, plot); if (ccv != null) { switch (ccv.getDeviceSampleStatus()) { case MULTIPLE_SAMPLES_MANY_VALUES: commentMarker = CommentMarker.MULTIPLE_VALUES; tttResult = commentMarker.toolTipText; break; case MULTIPLE_SAMPLES_ONE_VALUE: commentMarker = CommentMarker.MULTIPLE_WITH_ONE_VALUE; tttResult = commentMarker.toolTipText; break; case NO_DEVICE_SAMPLES: break; case ONE_DEVICE_SAMPLE: break; default: break; } switch (ccv.getEditState()) { case CURATED: break; case MORE_RECENT: // Note: may override MULTIPLE_SAMPLES Pair<CommentMarker, String> pair = moreRecentUnlessSameValue(ccv); commentMarker = pair.first; tttResult = pair.second; sampleIconType = SampleIconType.RAW; break; case RAW_SAMPLE: sampleIconType = SampleIconType.RAW; break; case FROM_DATABASE: sampleIconType = SampleIconType.DATABASE; break; case NO_VALUES: sampleIconType = SampleIconType.NORMAL; break; default: sampleIconType = SampleIconType.NORMAL; break; } } } String traitInstanceName = traitNameStyle.makeTraitInstanceName(instance, trait); CurationCellValue ccv = curationTableModel.getCurationCellValueForTraitInstanceInPlot(instance, plot); if (ccv != null) { ValidationRule vrule = null; try { String vrs = trait.getTraitValRule(); if (vrs != null && !vrs.isEmpty()) { vrule = ValidationRule.create(vrs); } } catch (InvalidRuleException e) { Log.w("PlotCellRenderer", "getTableCellRendererComponent." + traitInstanceName, e); } String wrapStart = ""; String wrapEnd = ""; KdxSample sample = ccv.getEditStateSampleMeasurement(); String valueFromSample = ""; if (sample != null) { EditState editState = ccv.getEditState(); if (editState != null) { wrapStart = editState.font.getWrapPrefix(); wrapEnd = editState.font.getWrapSuffix(); if (sample.isSuppressed()) { wrapStart = "<s>" + wrapStart; wrapEnd = wrapEnd + "</s>"; } } TraitValue traitValue = TraitInstanceValueRetriever.makeTraitValue(sample, instance, vrule, trialPlantingDate); valueFromSample = traitValue.displayValue; } sb.append(sep); if (wrapStart.isEmpty()) { sb.append(StringUtil.htmlEscape(traitInstanceName)); } else { sb.append(wrapStart).append(StringUtil.htmlEscape(traitInstanceName)).append("="); } Comparable<?> value = tempMap.get(instance); if (value != null) { sb.append(StringUtil.htmlEscape(value.toString())); } else { sb.append(StringUtil.htmlEscape(valueFromSample)); } sb.append(wrapEnd); } sep = "<br>"; } // each traitInstance } // each traitId return tttResult; }
From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartComponent.java
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$ PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$ definitionPath);/*from w w w . j a va 2s . c o m*/ errorElement.addElement("message").setText(message); //$NON-NLS-1$ error(message); return result; } // create a pie definition from the XML definition dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); //$NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; //$NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$ } if (height == -1) { height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$ } } catch (Exception e) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$ .getText(); } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$ } Element root = result.addElement("charts"); //$NON-NLS-1$ TimeSeriesCollection chartDataDefinition = (TimeSeriesCollection) dataDefinition; if (chartDataDefinition.getSeriesCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); //$NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$ for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) { for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) { Number value = chartDataDefinition.getY(row, column); Comparable rowKey = chartDataDefinition.getSeriesKey(row); RegularTimePeriod columnKey = chartDataDefinition.getSeries(row).getTimePeriod(column); Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$ valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$ valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$ valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$ } } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$ chartElement.addElement("image").setText(fileName); //$NON-NLS-1$ } return result; }
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 w w w. j a va 2s .c o m 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.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent.java
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$ PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$ definitionPath);/*from w w w. ja v a 2 s .c om*/ errorElement.addElement("message").setText(message); //$NON-NLS-1$ error(message); return result; } // create a pie definition from the XML definition dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); //$NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; //$NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$ } } catch (NumberFormatException ignored) { // go with the default } try { if (height == -1) { height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$ } } catch (NumberFormatException ignored) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$ .getText(); } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$ } Element root = result.addElement("charts"); //$NON-NLS-1$ DefaultCategoryDataset chartDataDefinition = (DefaultCategoryDataset) dataDefinition; if (chartDataDefinition.getRowCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); //$NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$ for (int row = 0; row < chartDataDefinition.getRowCount(); row++) { for (int column = 0; column < chartDataDefinition.getColumnCount(); column++) { Number value = chartDataDefinition.getValue(row, column); Comparable rowKey = chartDataDefinition.getRowKey(row); Comparable columnKey = chartDataDefinition.getColumnKey(column); Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$ valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$ valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$ valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$ } } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$ chartElement.addElement("image").setText(fileName); //$NON-NLS-1$ } return result; }