List of usage examples for org.jfree.data.category CategoryDataset getRowKey
public Comparable getRowKey(int row);
From source file:org.talend.dataprofiler.chart.TOPChartService.java
@Override public String getSeriestKeyOfGanttChart(Object chart, int index) { CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot(); CategoryDataset dataset = plot.getDataset(); return dataset.getRowKey(index).toString(); }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
private void initCategoryPlot(JFreeChart chart, ChartModel chartModel, final IChartLinkGenerator linkGenerator) { initPlot(chart, chartModel);//from ww w.java2 s .c o m org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel .getPlot(); CategoryPlot categoryPlot = chart.getCategoryPlot(); Grid grid = twoAxisPlot.getGrid(); if (twoAxisPlot.getOrientation() != Orientation.HORIZONTAL) { Color color = (grid.getVerticalLineColor() != null ? new Color(0x00FFFFFF & grid.getVerticalLineColor()) : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR)); categoryPlot.setDomainGridlinesVisible(grid.getVerticalLinesVisible()); categoryPlot.setDomainGridlinePaint(color); color = (grid.getHorizontalLineColor() != null ? new Color(0x00FFFFFF & grid.getHorizontalLineColor()) : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR)); categoryPlot.setRangeGridlinesVisible(grid.getHorizontalLinesVisible()); categoryPlot.setRangeGridlinePaint(color); } else { Color color = (grid.getHorizontalLineColor() != null ? new Color(0x00FFFFFF & grid.getHorizontalLineColor()) : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR)); categoryPlot.setDomainGridlinesVisible(grid.getHorizontalLinesVisible()); categoryPlot.setDomainGridlinePaint(color); color = (grid.getVerticalLineColor() != null ? new Color(0x00FFFFFF & grid.getVerticalLineColor()) : new Color(0x00FFFFFF & Grid.DEFAULT_GRID_COLOR)); categoryPlot.setRangeGridlinesVisible(grid.getVerticalLinesVisible()); categoryPlot.setRangeGridlinePaint(color); } categoryPlot.setDomainGridlineStroke(new BasicStroke(1)); categoryPlot.setRangeGridlineStroke(new BasicStroke(1)); List<Integer> colors = getPlotColors(twoAxisPlot); for (int j = 0; j < categoryPlot.getDatasetCount(); j++) { if (linkGenerator != null) { categoryPlot.getRenderer(j).setBaseItemURLGenerator(new CategoryURLGenerator() { public String generateURL(CategoryDataset dataset, int series, int category) { return linkGenerator.generateLink(dataset.getRowKey(series).toString(), dataset.getColumnKey(category).toString(), dataset.getValue(series, category)); } }); } for (int i = 0; i < colors.size(); i++) { categoryPlot.getRenderer(j).setSeriesPaint(i, new Color(0x00FFFFFF & colors.get(i))); } } Font domainAxisFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getFontFamily(), twoAxisPlot.getDomainAxis().getFontStyle(), twoAxisPlot.getDomainAxis().getFontWeight(), twoAxisPlot.getDomainAxis().getFontSize()); Font rangeAxisFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getFontFamily(), twoAxisPlot.getRangeAxis().getFontStyle(), twoAxisPlot.getRangeAxis().getFontWeight(), twoAxisPlot.getRangeAxis().getFontSize()); Font rangeTitleFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getLegend().getFontFamily(), twoAxisPlot.getRangeAxis().getLegend().getFontStyle(), twoAxisPlot.getRangeAxis().getLegend().getFontWeight(), twoAxisPlot.getRangeAxis().getLegend().getFontSize()); Font domainTitleFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getLegend().getFontFamily(), twoAxisPlot.getDomainAxis().getLegend().getFontStyle(), twoAxisPlot.getDomainAxis().getLegend().getFontWeight(), twoAxisPlot.getDomainAxis().getLegend().getFontSize()); CategoryAxis domainAxis = categoryPlot.getDomainAxis(); ValueAxis rangeAxis = categoryPlot.getRangeAxis(); AxesLabels axesLabels = getAxesLabels(chartModel); if ((axesLabels.rangeAxisLabel.length() > 0) && (rangeTitleFont != null)) { rangeAxis.setLabelFont(rangeTitleFont); } if ((axesLabels.domainAxisLabel.length() > 0) && (domainTitleFont != null)) { domainAxis.setLabelFont(domainTitleFont); } LabelOrientation labelOrientation = twoAxisPlot.getHorizontalAxis().getLabelOrientation(); if ((labelOrientation != null) && (labelOrientation != LabelOrientation.HORIZONTAL)) { if (twoAxisPlot.getOrientation() == Orientation.HORIZONTAL) { if (labelOrientation == LabelOrientation.VERTICAL) { rangeAxis.setVerticalTickLabels(true); } } else { switch (labelOrientation) { case VERTICAL: domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); break; case DIAGONAL: domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); break; } } } if (domainAxisFont != null) { domainAxis.setTickLabelFont(domainAxisFont); } if (rangeAxisFont != null) { rangeAxis.setTickLabelFont(rangeAxisFont); } Number rangeMin = twoAxisPlot.getRangeAxis().getMinValue(); if (rangeMin != null) { rangeAxis.setLowerBound(rangeMin.doubleValue()); } Number rangeMax = twoAxisPlot.getRangeAxis().getMaxValue(); if (rangeMax != null) { rangeAxis.setUpperBound(rangeMax.doubleValue()); } }
From source file:com.android.ddmuilib.HeapPanel.java
/** * Creates the chart below the statistics table *///from w w w . j a v a 2 s . c o m private void createChart() { mAllocCountDataSet = new DefaultCategoryDataset(); mChart = ChartFactory.createBarChart(null, "Size", "Count", mAllocCountDataSet, PlotOrientation.VERTICAL, false, true, false); // get the font to make a proper title. We need to convert the swt font, // into an awt font. Font f = mStatisticsBase.getFont(); FontData[] fData = f.getFontData(); // event though on Mac OS there could be more than one fontData, we'll only use // the first one. FontData firstFontData = fData[0]; java.awt.Font awtFont = SWTUtils.toAwtFont(mStatisticsBase.getDisplay(), firstFontData, true /* ensureSameSize */); mChart.setTitle(new TextTitle("Allocation count per size", awtFont)); Plot plot = mChart.getPlot(); if (plot instanceof CategoryPlot) { // get the plot CategoryPlot categoryPlot = (CategoryPlot) plot; // set the domain axis to draw labels that are displayed even with many values. CategoryAxis domainAxis = categoryPlot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { // get the key for the size of the allocation ByteLong columnKey = (ByteLong) dataset.getColumnKey(column); String rowKey = (String) dataset.getRowKey(row); Number value = dataset.getValue(rowKey, columnKey); return String.format("%1$d %2$s of %3$d bytes", value.intValue(), rowKey, columnKey.getValue()); } }); } mChartComposite = new ChartComposite(mStatisticsBase, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 3000, // max draw width. We don't want it to zoom, so we put a big number 3000, // max draw height. We don't want it to zoom, so we put a big number true, // off-screen buffer true, // properties true, // save true, // print false, // zoom true); // tooltips mChartComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Creates a pie dataset from a {@link CategoryDataset} by taking all the * values for a single column.//from w ww . j ava 2 s.c om * * @param dataset the dataset (<code>null</code> not permitted). * @param column the column (zero-based index). * * @return A pie dataset. */ public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, int column) { DefaultPieDataset result = new DefaultPieDataset(); int rowCount = dataset.getRowCount(); for (int i = 0; i < rowCount; i++) { Comparable rowKey = dataset.getRowKey(i); result.setValue(rowKey, dataset.getValue(i, column)); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset.// w ww .ja va2 s . co m * @param map a structure that maps series to groups. * * @return The value range ({@code null} if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { Args.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // create an array holding the group indices for each series... int[] groupIndex = new int[dataset.getRowCount()]; for (int i = 0; i < dataset.getRowCount(); i++) { groupIndex[i] = map.getGroupIndex(map.getGroup(dataset.getRowKey(i))); } // minimum and maximum for each group... int groupCount = map.getGroupCount(); double[] minimum = new double[groupCount]; double[] maximum = new double[groupCount]; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double[] positive = new double[groupCount]; double[] negative = new double[groupCount]; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { positive[groupIndex[series]] = positive[groupIndex[series]] + value; } if (value < 0.0) { negative[groupIndex[series]] = negative[groupIndex[series]] + value; // '+', remember value is negative } } } for (int g = 0; g < groupCount; g++) { minimum[g] = Math.min(minimum[g], negative[g]); maximum[g] = Math.max(maximum[g], positive[g]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset.//from w w w . j a va 2 s .c o m * @param map a structure that maps series to groups. * * @return The value range (<code>null</code> if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { ParamChecks.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // create an array holding the group indices for each series... int[] groupIndex = new int[dataset.getRowCount()]; for (int i = 0; i < dataset.getRowCount(); i++) { groupIndex[i] = map.getGroupIndex(map.getGroup(dataset.getRowKey(i))); } // minimum and maximum for each group... int groupCount = map.getGroupCount(); double[] minimum = new double[groupCount]; double[] maximum = new double[groupCount]; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double[] positive = new double[groupCount]; double[] negative = new double[groupCount]; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { positive[groupIndex[series]] = positive[groupIndex[series]] + value; } if (value < 0.0) { negative[groupIndex[series]] = negative[groupIndex[series]] + value; // '+', remember value is negative } } } for (int g = 0; g < groupCount; g++) { minimum[g] = Math.min(minimum[g], negative[g]); maximum[g] = Math.max(maximum[g], positive[g]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataSet, int row, int column, int pass) { if (!getItemVisible(row, column)) { return;/* w w w . ja v a 2s . c om*/ } Number value = dataSet.getValue(row, column); int visibleRow = state.getVisibleSeriesIndex(row); if ((value == null || visibleRow < 0)) { return; } LineFillItemRendererState rendererState = (LineFillItemRendererState) state; double currentValue = value.doubleValue(); double currentItemXPoint = calculateItemXPoint(plot, dataSet, domainAxis, dataArea, column, visibleRow, state.getVisibleSeriesCount()); double currentItemYPoint = calculateItemYPoint(plot, rangeAxis, dataArea, currentValue); if (isAreaAndLinePass(pass)) { processAreaAndLine(dataArea, plot, domainAxis, rangeAxis, dataSet, rendererState, row, column, currentValue, currentItemXPoint, currentItemYPoint, visibleRow); } else if (isShapesAndLabelsPass(pass)) { Shape entityArea = renderItemShapeAndLabel(g2, dataSet, row, column, plot.getOrientation(), currentValue, currentItemXPoint, currentItemYPoint); int dataSetIndex = plot.indexOf(dataSet); updateCrosshairValues(state.getCrosshairState(), dataSet.getRowKey(row), dataSet.getColumnKey(column), currentValue, dataSetIndex, currentItemXPoint, currentItemYPoint, plot.getOrientation()); EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataSet, row, column, entityArea); } } }
From source file:extern.NpairsBoxAndWhiskerRenderer.java
/** * Returns a legend item for a series./*from w ww. j av a 2 s .co m*/ * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return The legend item (possibly <code>null</code>). */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot cp = getPlot(); if (cp == null) { return null; } // check that a legend item needs to be displayed... if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) { return null; } CategoryDataset dataset = cp.getDataset(datasetIndex); String label = getLegendItemLabelGenerator().generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0); Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); LegendItem result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getRowKey(series)); result.setSeriesIndex(series); return result; }
From source file:edu.dlnu.liuwenpeng.render.LineAndShapeRenderer.java
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { ls.add(dataset.getValue(0, column).doubleValue()); if (!getItemVisible(row, column)) { return;/*from ww w . j a v a 2 s . c om*/ } if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) { return; } // nothing is drawn for null... Number v = dataset.getValue(row, column); if (v == null) { return; } PlotOrientation orientation = plot.getOrientation(); // current data point... double x1; if (this.useSeriesOffset) { x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column), dataset.getRowKey(row), dataset, this.itemMargin, dataArea, plot.getDomainAxisEdge()); } else { x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); } double value = v.doubleValue(); double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); if (pass == 0 && getItemLineVisible(row, column)) { if (column != 0) { Number previousValue = dataset.getValue(row, column - 1); if (previousValue != null) { // previous data point... double previous = previousValue.doubleValue(); double x0; if (this.useSeriesOffset) { x0 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column - 1), dataset.getRowKey(row), dataset, this.itemMargin, dataArea, plot.getDomainAxisEdge()); } else { x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge()); } double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(y0, x0, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(x0, y0, x1, y1); } g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.draw(line); } } } if (pass == 1) { Shape shape = getItemShape(row, column); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); } if (getItemShapeVisible(row, column)) { if (getItemShapeFilled(row, column)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.fill(shape); } if (this.drawOutlines) { if (this.useOutlinePaint) { g2.setPaint(getItemOutlinePaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.setStroke(getItemOutlineStroke(row, column)); g2.draw(shape); } } // draw the item label if there is one... if (isItemLabelVisible(row, column)) { if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0)); } else if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0)); } } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, shape); } } if (i == dataset.getColumnCount() - 1) { average = GetAverage.getAverage(ls); double averangeline = rangeAxis.valueToJava2D(average, dataArea, plot.getRangeAxisEdge()); double x = rangeAxis.valueToJava2D(dataset.getColumnCount() - 1, dataArea, plot.getDomainAxisEdge()); Line2D line2d = new Line2D.Double(0, averangeline, x, averangeline); g2.setPaint(Color.white); g2.draw(line2d); i = 0; ls.clear(); } i++; }
From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java
/** * Returns a legend item for a series. * /*w w w . j a va 2 s. c o m*/ * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return The legend item (possibly <code>null</code>). */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot cp = getPlot(); if (cp == null) { return null; } // check that a legend item needs to be displayed... if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) { return null; } CategoryDataset dataset = cp.getDataset(datasetIndex); String label = getLegendItemLabelGenerator().generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0); Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); LegendItem result = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black); result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getRowKey(series)); result.setSeriesIndex(series); if (this.gradientPaintTransformer != null) { result.setFillPaintTransformer(this.gradientPaintTransformer); } return result; }