List of usage examples for org.jfree.data.category CategoryDataset getRowKey
public Comparable getRowKey(int row);
From source file:org.openfaces.component.chart.impl.helpers.ChartInfoUtil.java
private static GridPointInfo getGridPointInfo(CategoryItemEntity en, Chart chart) { ChartModel model = chart.getModel(); if (model == null) return null; GridPointInfo info = new GridPointInfoImpl(); info.setSeries(new SeriesInfoImpl()); info.getSeries().setIndex(en.getSeries()); ModelInfo modelInfo = new ModelInfo(model); if (!modelInfo.isDataEmpty()) { CategoryDataset ds = ModelConverter.toCategoryDataset(modelInfo); Comparable seriesKey = ds.getRowKey(en.getSeries()); Comparable tupleKey = ds.getColumnKey(en.getCategoryIndex()); Object tupleValue = ds.getValue(seriesKey, tupleKey); info.setIndex(en.getCategoryIndex()); info.setKey(tupleKey);// w w w . j a v a 2 s .com info.setValue(tupleValue); info.getSeries().setKey(seriesKey); } return info; }
From source file:hudson.graph.jfreechart.Utils.java
/** * Adjusts the Y-axis so that abnormally large value won't spoil the whole chart * by making everything look virtually 0. * * <p>/*ww w . j a v a 2 s.co m*/ * The algorithm is based on <a href="http://en.wikipedia.org/wiki/Chebyshev%27s_inequality">Chebyshev's inequality</a>, * which states that given any number sequence, nore more than 1/(N^2) values are more than N x stddev away * from the average. * * <p> * So the algorithm is to set Y-axis range so that we can see all data points that are within N x stddev * of the average. Most of the time, Cebyshev's inequality is very conservative, so it shouldn't do * much harm. * * <p> * When the algorithm does kick in, however, we can kick out at most 1 in N^2 data points. * (So for example if N=3 then we can "fix" the graph as long as we only have less than 1/(3*3)=11.111...% bad data. * * <p> * Also see issue #1246. */ public static void adjustChebyshev(CategoryDataset dataset, NumberAxis yAxis) { // first compute E(X) and Var(X) double sum = 0, sum2 = 0; final int nColumns = dataset.getColumnCount(); final int nRows = dataset.getRowCount(); for (int i = 0; i < nRows; i++) { Comparable rowKey = dataset.getRowKey(i); for (int j = 0; j < nColumns; j++) { Comparable columnKey = dataset.getColumnKey(j); double n = dataset.getValue(rowKey, columnKey).doubleValue(); sum += n; sum2 += n * n; } } double average = sum / (nColumns * nRows); double stddev = Math.sqrt(sum2 / (nColumns * nRows) - average * average); double rangeMin = average - stddev * CHEBYSHEV_N; double rangeMax = average + stddev * CHEBYSHEV_N; // now see if there are any data points that fall outside (rangeMin,rangeMax) boolean found = false; double min = 0, max = 0; for (int i = 0; i < nRows; i++) { Comparable rowKey = dataset.getRowKey(i); for (int j = 0; j < nColumns; j++) { Comparable columnKey = dataset.getColumnKey(j); double n = dataset.getValue(rowKey, columnKey).doubleValue(); if (n < rangeMin || rangeMax < n) { found = true; continue; // ignore this value } min = Math.min(min, n); max = Math.max(max, n); } } if (!found) return; // no adjustment was necessary // some values fell outside the range, so adjust the Y-axis // if we are ever to extend this method to handle negative value ranges correctly, // the code after this needs modifications min = Math.min(0, min); // always include 0 in the graph max += yAxis.getUpperMargin() * (max - min); yAxis.setRange(min, max); }
From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartWriter.java
public static void writeChartDataToFile(String filename, JFreeChart chart) { filename += ".txt"; try {/*from ww w .j a v a2 s. c o m*/ BufferedWriter writer = IOUtils.getBufferedWriter(filename); try { /*read "try" as if (plot instanceof XYPlot)*/ XYPlot xy = chart.getXYPlot(); String yAxisLabel = xy.getRangeAxis().getLabel(); String xAxisLabel = ""; if (xy.getDomainAxis() != null) { xAxisLabel = xy.getDomainAxis().getLabel(); } String header = xAxisLabel + "\t " + yAxisLabel; writer.write(header); writer.newLine(); for (int i = 0; i < xy.getDatasetCount(); i++) { XYDataset xyds = xy.getDataset(i); for (int seriesIndex = 0; seriesIndex < xyds.getSeriesCount(); seriesIndex++) { writer.newLine(); writer.write("Series " + "'" + xyds.getSeriesKey(seriesIndex).toString()); writer.write("'"); writer.newLine(); int items = xyds.getItemCount(seriesIndex); for (int itemsIndex = 0; itemsIndex < items; itemsIndex++) { Number xValue = xyds.getX(seriesIndex, itemsIndex); Number yValue = xyds.getY(seriesIndex, itemsIndex); writer.write(xValue.toString()); writer.write("\t"); writer.write(yValue.toString()); writer.newLine(); } } } System.out.println("Table written to : " + filename + "\n" + "=================================================="); } catch (ClassCastException e) { //else instanceof CategoryPlot log.info("caught class cast exception, trying to write CategoryPlot"); CategoryPlot cp = chart.getCategoryPlot(); String header = "CategoryRowKey \t CategoryColumnKey \t CategoryRowIndex \t CategoryColumnIndex \t Value"; writer.write(header); writer.newLine(); for (int i = 0; i < cp.getDatasetCount(); i++) { CategoryDataset cpds = cp.getDataset(i); for (int rowIndex = 0; rowIndex < cpds.getRowCount(); rowIndex++) { for (int columnIndex = 0; columnIndex < cpds.getColumnCount(); columnIndex++) { Number value = cpds.getValue(rowIndex, columnIndex); writer.write(cpds.getRowKey(rowIndex).toString()); writer.write("\t"); writer.write(cpds.getColumnKey(columnIndex).toString()); writer.write("\t"); writer.write(Integer.toString(rowIndex)); writer.write("\t"); writer.write(Integer.toString(columnIndex)); writer.write("\t"); writer.write(value.toString()); writer.newLine(); } } } } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:playground.dgrether.analysis.charts.utils.DgChartWriter.java
public static void writeChartDataToFile(String filename, JFreeChart chart) { filename += ".txt"; try {/*from w w w.j a v a2 s .com*/ BufferedWriter writer = IOUtils.getBufferedWriter(filename); try { /*read "try" as if (plot instanceof XYPlot)*/ XYPlot xy = chart.getXYPlot(); String yAxisLabel = xy.getRangeAxis().getLabel(); String xAxisLabel = ""; if (xy.getDomainAxis() != null) { xAxisLabel = xy.getDomainAxis().getLabel(); } String header = "#" + xAxisLabel + "\t " + yAxisLabel; writer.write(header); writer.newLine(); //write the header writer.write("#"); for (int i = 0; i < xy.getDatasetCount(); i++) { XYDataset xyds = xy.getDataset(i); int seriesIndex = 0; int maxItems = 0; int seriesCount = xyds.getSeriesCount(); while (seriesIndex < seriesCount) { writer.write("Series " + xyds.getSeriesKey(seriesIndex).toString()); if (seriesIndex < seriesCount - 1) { writer.write("\t \t"); } if (xyds.getItemCount(seriesIndex) > maxItems) { maxItems = xyds.getItemCount(seriesIndex); } seriesIndex++; } writer.newLine(); //write the data Number xValue, yValue = null; for (int itemsIndex = 0; itemsIndex < maxItems; itemsIndex++) { for (int seriesIdx = 0; seriesIdx < seriesCount; seriesIdx++) { if (seriesIdx < xyds.getSeriesCount() && itemsIndex < xyds.getItemCount(seriesIdx)) { xValue = xyds.getX(seriesIdx, itemsIndex); yValue = xyds.getY(seriesIdx, itemsIndex); if (xValue != null && yValue != null) { writer.write(xValue.toString()); writer.write("\t"); writer.write(yValue.toString()); if (seriesIdx < seriesCount - 1) { writer.write("\t"); } } } } writer.newLine(); } } } catch (ClassCastException e) { //else instanceof CategoryPlot log.info("Due to a caught class cast exception, it should be a CategoryPlot"); CategoryPlot cp = chart.getCategoryPlot(); String header = "# CategoryRowKey \t CategoryColumnKey \t CategoryRowIndex \t CategoryColumnIndex \t Value"; writer.write(header); writer.newLine(); for (int i = 0; i < cp.getDatasetCount(); i++) { CategoryDataset cpds = cp.getDataset(i); for (int rowIndex = 0; rowIndex < cpds.getRowCount(); rowIndex++) { for (int columnIndex = 0; columnIndex < cpds.getColumnCount(); columnIndex++) { Number value = cpds.getValue(rowIndex, columnIndex); writer.write(cpds.getRowKey(rowIndex).toString()); writer.write("\t"); writer.write(cpds.getColumnKey(columnIndex).toString()); writer.write("\t"); writer.write(Integer.toString(rowIndex)); writer.write("\t"); writer.write(Integer.toString(columnIndex)); writer.write("\t"); writer.write(value.toString()); writer.newLine(); } } } } writer.close(); log.info("Chart data written to: " + filename); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.ucla.stat.SOCR.chart.gui.CustomCategoryItemLabelGenerator.java
/** * Generates an item label.//from w w w . j a v a 2 s . c om * * @param dataset the dataset. * @param series the series index. * @param category the category index. * * @return the label. */ public String generateItemLabel(CategoryDataset dataset, int series, int category) { return dataset.getRowKey(series).toString(); }
From source file:com.googlecode.logVisualizer.chart.perDayConsumption.ConsumptionLableGenerator.java
public String generateRowLabel(final CategoryDataset dataset, final int row) { return dataset.getRowKey(row).toString(); }
From source file:lucee.runtime.chart.CategoryToolTipGeneratorImpl.java
public String generateToolTip(CategoryDataset dataset, int row, int column) { String r = dataset.getRowKey(row).toString(); String c = dataset.getColumnKey(column).toString(); String both = r + "," + c; if (StringUtil.isEmpty(r)) both = c;/*ww w. j a v a2 s. c om*/ if (StringUtil.isEmpty(c)) both = r; return LabelFormatUtil.format(labelFormat, dataset.getValue(row, column).doubleValue()) + " (" + both + ")"; }
From source file:scheduler.benchmarker.manager.CustomBarRenderer.java
@Override public Paint getItemPaint(int x_row, int x_col) { CategoryDataset cDataset = getPlot().getDataset(); String ruleName = (String) cDataset.getRowKey(x_row); return pluginColors.getColorForRule(ruleName); }
From source file:scheduler.benchmarker.manager.CustomBarRenderer.java
@Override public Paint getItemLabelPaint(int x_row, int x_col) { CategoryDataset cDataset = getPlot().getDataset(); String ruleName = (String) cDataset.getRowKey(x_row); if (ruleName.startsWith("IDLE")) return pluginColors.getColorForRule("IDLE"); else/*from w w w . j a va 2 s .c o m*/ return Color.BLACK; }
From source file:net.sf.jasperreports.charts.util.CategoryLabelGenerator.java
@Override public String generateLabel(CategoryDataset dataset, int series, int category) { Comparable<?> seriesName = dataset.getRowKey(series); Map<Comparable<?>, String> labels = labelsMap.get(seriesName); if (labels != null) { return labels.get(dataset.getColumnKey(category)); }/*w w w.j a v a 2s. c om*/ return super.generateLabel(dataset, series, category); }