List of usage examples for org.jfree.data.category DefaultCategoryDataset getValue
@Override
public Number getValue(Comparable rowKey, Comparable columnKey)
From source file:org.jfree.data.category.DefaultCategoryDatasetTest.java
/** * Some basic checks for the removeValue() method. *///ww w. ja va2s . c om public void testRemoveValue() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.removeValue("R1", "C1"); d.addValue(new Double(1.0), "R1", "C1"); d.removeValue("R1", "C1"); assertEquals(0, d.getRowCount()); assertEquals(0, d.getColumnCount()); d.addValue(new Double(1.0), "R1", "C1"); d.addValue(new Double(2.0), "R2", "C1"); d.removeValue("R1", "C1"); assertEquals(new Double(2.0), d.getValue(0, 0)); boolean pass = false; try { d.removeValue(null, "C1"); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { d.removeValue("R1", null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.emftrace.quarc.ui.views.RatioView.java
/** * create a SpiderChart // ww w. java2 s .co m * @param dataset the dataset for the chart * @param weighted include weights? * @return the created SpiderChart */ private JFreeChart createSpiderChart(DefaultCategoryDataset dataset, boolean weighted) { SpiderWebPlot plot = new SpiderWebPlot(dataset); plot.setMaxValue(200.0f); plot.setStartAngle(54); plot.setInteriorGap(0.40); plot.setToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int section, int index) { Float ratingValue = (Float) dataset.getValue(section, index); if (ratingValue == null) ratingValue = 0.0f; else ratingValue -= 100.0f; return String.valueOf("(" + dataset.getRowKey(section) + "," + dataset.getColumnKey(index) + ") = " + String.format("%.2f", ratingValue)); } }); plot.setNoDataMessage("No data to display"); String titleStr = "ratings of selected elements"; if (weighted) titleStr = "weighted " + titleStr; JFreeChart chart = new JFreeChart(titleStr, TextTitle.DEFAULT_FONT, plot, false); LegendTitle legend = new LegendTitle(plot); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); ChartUtilities.applyCurrentTheme(chart); return chart; }
From source file:uk.ac.lkl.cram.ui.report.Report.java
private void addLearningExperience() { MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); mdp.addStyledParagraphOfText("Heading1", "Learning Experience"); LearningExperienceChartMaker maker = new LearningExperienceChartMaker(module); JFreeChart chart = maker.getChartPanel().getChart(); DefaultCategoryDataset dataset = (DefaultCategoryDataset) maker.getDataset(); Tbl table = factory.createTbl();/*from www. j a v a 2 s.c o m*/ double total = 0f; Comparable columnKey = (Comparable) dataset.getColumnKeys().get(0); for (Object key : dataset.getRowKeys()) { total += (Double) dataset.getValue((Comparable) key, columnKey); } boolean first = true; for (Object key : dataset.getRowKeys()) { Tr tableRow = factory.createTr(); Tc tableCell = factory.createTc(); TcPr tcpr = factory.createTcPr(); tableCell.setTcPr(tcpr); VMerge vMerge = factory.createTcPrInnerVMerge(); tcpr.setVMerge(vMerge); if (first) { vMerge.setVal("restart"); /* Specify the height and width of the Pie Chart */ int width = (int) (480f * 0.9f); /* Width of the chart */ int height = (int) (180f * 0.9f); /* Height of the chart */ tableCell.getContent().add(createChart(chart, width, height)); first = false; } else { tableCell.getContent().add(factory.createP()); } tableRow.getContent().add(tableCell); double percent = (Double) dataset.getValue((Comparable) key, columnKey) / total; addSimpleTableCell(tableRow, key.toString()); addTableCell(tableRow, PERCENT_FORMATTER.format(percent), JcEnumeration.RIGHT, false); table.getContent().add(tableRow); } addBorders(table); mdp.addObject(table); }
From source file:org.jfree.data.category.junit.DefaultCategoryDatasetTests.java
/** * Some basic checks for the removeValue() method. *//* w w w .jav a2s. c om*/ public void testRemoveValue() { DefaultCategoryDataset d = new DefaultCategoryDataset(); // if we try removing with unknown keys, we expect an exception boolean pass = false; try { d.removeValue("R1", "C1"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); d.addValue(new Double(1.0), "R1", "C1"); d.removeValue("R1", "C1"); assertEquals(0, d.getRowCount()); assertEquals(0, d.getColumnCount()); d.addValue(new Double(1.0), "R1", "C1"); d.addValue(new Double(2.0), "R2", "C1"); d.removeValue("R1", "C1"); assertEquals(new Double(2.0), d.getValue(0, 0)); pass = false; try { d.removeValue(null, "C1"); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { d.removeValue("R1", null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:ispd.gui.auxiliar.Graficos.java
private JFreeChart criarGraficoEstadoTarefa2(List<Tarefa> tarefas, RedeDeFilas rdf) { DefaultCategoryDataset dados = new DefaultCategoryDataset(); for (CS_Processamento maq : rdf.getMaquinas()) { dados.addValue(0, "Canceled", maq.getId()); dados.addValue(0, "Completed", maq.getId()); dados.addValue(0, "Not executed", maq.getId()); dados.addValue(0, "Failures", maq.getId()); }//from w w w.jav a 2 s.c om for (CS_Processamento maq : rdf.getMestres()) { if (maq instanceof CS_Mestre) { dados.addValue(0, "Canceled", maq.getId()); dados.addValue(0, "Completed", maq.getId()); dados.addValue(0, "Not executed", maq.getId()); dados.addValue(0, "Failures", maq.getId()); } } for (Tarefa tarefa : tarefas) { Double val; switch (tarefa.getEstado()) { case Tarefa.PARADO: val = (Double) dados.getValue("Not executed", tarefa.getOrigem().getId()); dados.setValue(val + 1, "Not executed", tarefa.getOrigem().getId()); break; case Tarefa.CONCLUIDO: val = (Double) dados.getValue("Completed", tarefa.getLocalProcessamento().getId()); dados.setValue(val + 1, "Completed", tarefa.getLocalProcessamento().getId()); break; case Tarefa.CANCELADO: val = (Double) dados.getValue("Canceled", tarefa.getLocalProcessamento().getId()); dados.setValue(val + 1, "Canceled", tarefa.getLocalProcessamento().getId()); break; case Tarefa.FALHA: val = (Double) dados.getValue("Failures", tarefa.getLocalProcessamento().getId()); dados.setValue(val + 1, "Failures", tarefa.getLocalProcessamento().getId()); break; } } JFreeChart jfc = ChartFactory.createBarChart("State of tasks per resource", //Titulo "Resource", // Eixo X "Numbers of tasks", //Eixo Y dados, // Dados para o grafico PlotOrientation.VERTICAL, //Orientacao do grafico true, false, false); // exibir: legendas, tooltips, url return jfc; }
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);/*www . j a v a 2 s.com*/ 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; }
From source file:uk.ac.lkl.cram.ui.report.Report.java
private void addLearnerFeedback() { MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); mdp.addStyledParagraphOfText("Heading1", "Source of Learner Feedback"); FeedbackChartMaker maker = new FeedbackChartMaker(module); JFreeChart chart = maker.getChartPanel().getChart(); DefaultCategoryDataset dataset = (DefaultCategoryDataset) maker.getDataset(); Tbl table = factory.createTbl();/*from w w w . java 2 s . com*/ Comparable columnKey = (Comparable) dataset.getColumnKeys().get(0); boolean first = true; for (Object key : dataset.getRowKeys()) { Tr tableRow = factory.createTr(); Tc tableCell = factory.createTc(); TcPr tcpr = factory.createTcPr(); tableCell.setTcPr(tcpr); VMerge vMerge = factory.createTcPrInnerVMerge(); tcpr.setVMerge(vMerge); if (first) { vMerge.setVal("restart"); /* Specify the height and width of the Pie Chart */ int width = (int) (480f * 0.8f); /* Width of the chart */ int height = (int) (360f * 0.8f); /* Height of the chart */ tableCell.getContent().add(createChart(chart, width, height)); first = false; } else { tableCell.getContent().add(factory.createP()); } tableRow.getContent().add(tableCell); double value = (Double) dataset.getValue((Comparable) key, columnKey); addSimpleTableCell(tableRow, key.toString()); addTableCell(tableRow, FLOAT_FORMATTER.format(value) + " hours", JcEnumeration.RIGHT, false); table.getContent().add(tableRow); } addBorders(table); mdp.addObject(table); }
From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java
private File createImage(ApplicationGroup appgroup) throws IOException { Map<String, Double> costs = Maps.newHashMap(); DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0); Interval interval = new Interval(end.minusWeeks(numWeeks), end); for (Product product : products) { List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product); if (resourceGroups.size() == 0) { continue; }/* w w w .j av a 2s . com*/ DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly); if (dataManager == null) { continue; } TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null, resourceGroups); Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none, false); for (Tag tag : data.keySet()) { for (int week = 0; week < numWeeks; week++) { String key = tag + "|" + week; if (costs.containsKey(key)) costs.put(key, data.get(tag)[week] + costs.get(key)); else costs.put(key, data.get(tag)[week]); } } } boolean hasData = false; for (Map.Entry<String, Double> entry : costs.entrySet()) { if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) { hasData = true; break; } } if (!hasData) return null; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Product product : products) { for (int week = 0; week < numWeeks; week++) { String weekStr = String.format("%s - %s week", formatter.print(end.minusWeeks(numWeeks - week)).substring(5), formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5)); dataset.addValue(costs.get(product + "|" + week), product.name, weekStr); } } JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "", "Costs", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer(); renderer.setItemLabelAnchorOffset(10.0); TextTitle title = chart.getTitle(); title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3))); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() { public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row, int column) { return costFormatter.format(dataset.getValue(row, column)); } }); renderer.setBaseItemLabelsVisible(true); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setNumberFormatOverride(costFormatter); BufferedImage image = chart.createBufferedImage(1200, 400); File outputfile = File.createTempFile("awscost", "png"); ImageIO.write(image, "png", outputfile); return outputfile; }
From source file:com.compomics.pepshell.view.statistics.RatioStatisticsPane.java
private CategoryDataset createRatioDataset(PepshellProtein aPepshellProtein) { DefaultCategoryDataset returnset = new DefaultCategoryDataset(); //PepshellProtein protein = experimentGroup.get(0).getProteins().get(experimentGroup.get(0).getProteins().indexOf(aPepshellProtein)); if (aPepshellProtein != null) { for (Experiment anExperiment : experimentGroup) { if (anExperiment.getProteins().indexOf(aPepshellProtein) != -1) { PepshellProtein protein = anExperiment.getProteins() .get(anExperiment.getProteins().indexOf(aPepshellProtein)); List<PeptideGroup> sortedCopy = protein.getPeptideGroups().stream() .sorted(Comparator .comparing(e -> e.getRepresentativePeptide().getBeginningProteinMatch())) .collect(Collectors.toList()); for (PeptideGroup aPeptideGroup : sortedCopy) { PeptideInterface aPeptide = aPeptideGroup.getRepresentativePeptide(); if (aPeptide instanceof QuantedPeptide && ((QuantedPeptide) aPeptide).getRatio() != null) { Double value = Math.log(((QuantedPeptide) aPeptide).getRatio()) / Math.log(2); returnset.addValue(value, anExperiment.getExperimentName(), String.valueOf(aPeptide.getBeginningProteinMatch())); //this part can be put in it's own method for (Experiment checkList : experimentGroup) { if (!checkList.equals(anExperiment) && returnset.getRowKeys().contains(checkList.getExperimentName())) { if (returnset.getValue(checkList.getExperimentName(), String.valueOf(aPeptide.getBeginningProteinMatch())) == null) { returnset.addValue(null, checkList.getExperimentName(), String.valueOf(aPeptide.getBeginningProteinMatch())); }//w w w . j a v a 2s . c om } } } } } } } return returnset; }
From source file:org.leo.benchmark.Benchmark.java
/** * Create a chartpanel//from w w w . ja v a2 s . c o m * * @param title title * @param dataName name of the data * @param clazzResult data mapped by classes * @param catItemLabelGenerator label generator * @return the chartPanel */ @SuppressWarnings("serial") private ChartPanel createChart(String title, String dataName, Map<Class<? extends Collection<?>>, Long> clazzResult, AbstractCategoryItemLabelGenerator catItemLabelGenerator) { // sort data by class name List<Class<? extends Collection<?>>> clazzes = new ArrayList<Class<? extends Collection<?>>>( clazzResult.keySet()); Collections.sort(clazzes, new Comparator<Class<? extends Collection<?>>>() { @Override public int compare(Class<? extends Collection<?>> o1, Class<? extends Collection<?>> o2) { return o1.getCanonicalName().compareTo(o2.getCanonicalName()); } }); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); // add the data to the dataset for (Class<? extends Collection<?>> clazz : clazzes) { dataSet.addValue(clazzResult.get(clazz), clazz.getName(), title.split(" ")[0]); } // create the chart JFreeChart chart = ChartFactory.createBarChart3D(null, null, dataName, dataSet, PlotOrientation.HORIZONTAL, false, true, false); chart.addSubtitle(new TextTitle(title)); // some customization in the style CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(250, 250, 250)); plot.setDomainGridlinePaint(new Color(255, 200, 200)); plot.setRangeGridlinePaint(Color.BLUE); plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setLabelFont(new Font("arial", Font.PLAIN, 10)); BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); // display the class name in the bar chart for (int i = 0; i < clazzResult.size(); i++) { renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator() { @Override public String generateLabel(CategoryDataset dataset, int row, int column) { String label = " " + dataset.getRowKey(row).toString(); if (dataset.getValue(row, column).equals(timeout * 1000000)) { label += " (Timeout)"; } return label; } }); renderer.setSeriesItemLabelsVisible(i, true); ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0); renderer.setSeriesPositiveItemLabelPosition(i, itemPosition); renderer.setSeriesNegativeItemLabelPosition(i, itemPosition); } ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0); renderer.setPositiveItemLabelPositionFallback(itemPosition); renderer.setNegativeItemLabelPositionFallback(itemPosition); renderer.setShadowVisible(false); // create the chartpanel ChartPanel chartPanel = new ChartPanel(chart); chart.setBorderVisible(true); return chartPanel; }