List of usage examples for org.jfree.data.category CategoryDataset getValue
public Number getValue(Comparable rowKey, Comparable columnKey);
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);/* ww w .j a v a2 s . c o m*/ info.setValue(tupleValue); info.getSeries().setKey(seriesKey); } return info; }
From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartWriter.java
public static void writeChartDataToFile(String filename, JFreeChart chart) { filename += ".txt"; try {/* w w w. ja va2s. c om*/ 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 ww w . ja 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(); //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:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param entity//from ww w.j a v a 2 s .c o m * @param chartPanel * @param dataset * @param seriesIndex * @param itemIndex * @return */ public static Shape toView(Shape entity, ChartPanel chartPanel, Dataset dataset, int seriesIndex, int itemIndex) { if (dataset instanceof XYDataset) { XYDataset xyds = (XYDataset) dataset; double x1 = xyds.getXValue(seriesIndex, itemIndex); double y1 = xyds.getYValue(seriesIndex, itemIndex); AffineTransform toPosition = getModelToViewTransformXY(chartPanel, x1, y1); toPosition.concatenate( getTranslateInstance(-entity.getBounds2D().getCenterX(), -entity.getBounds2D().getCenterY())); return toPosition.createTransformedShape(entity); } else if (dataset instanceof CategoryDataset) { CategoryDataset cds = (CategoryDataset) dataset; double y1 = cds.getValue(seriesIndex, itemIndex).doubleValue(); AffineTransform toPosition = getModelToViewTransformCategory(chartPanel, itemIndex, y1); toPosition.concatenate( getTranslateInstance(-entity.getBounds2D().getCenterX(), -entity.getBounds2D().getCenterY())); return toPosition.createTransformedShape(entity); } throw new IllegalArgumentException("Unsupported dataset type: " + dataset.getClass()); }
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>//w ww .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:org.talend.dataprofiler.chart.util.TopChartFactory.java
private static double sumGroupCount(CategoryDataset categorydataset) { double groupCount = 0.0; for (int i = 0; i < categorydataset.getColumnCount(); i++) { groupCount += categorydataset.getValue(0, i).doubleValue(); }/*from w w w. ja v a2s . com*/ return groupCount; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
private static double sumItemCount(CategoryDataset categorydataset) { double itemCount = 0; for (int i = 0; i < categorydataset.getColumnCount(); i++) { int columnKey = Integer.valueOf(categorydataset.getColumnKey(i).toString()); itemCount += categorydataset.getValue(0, i).intValue() * columnKey; }//from w w w. j a va 2s. co m return itemCount; }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.LabelGenerator.java
public String generateLabel(CategoryDataset dataset, int series) { return dataset.getValue(0, series).toString(); }
From source file:jenkins.plugins.livingdoc.chart.NumberLabelGenerator.java
public String generateLabel(CategoryDataset dataset, int row, int column) { Number value = dataset.getValue(row, column); return value == null || value.intValue() == 0 ? null : String.valueOf(value.intValue()); }
From source file:com.bdb.weather.display.RainItemLabelGenerator.java
@Override public String generateLabel(CategoryDataset dataset, int row, int column) { Number value = dataset.getValue(row, column); if (value.doubleValue() == 0.0) return null; else/*from ww w . j av a 2 s . c o m*/ return super.generateLabel(dataset, row, column); }