Example usage for org.jfree.data.category DefaultCategoryDataset getColumnKey

List of usage examples for org.jfree.data.category DefaultCategoryDataset getColumnKey

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset getColumnKey.

Prototype

@Override
public Comparable getColumnKey(int column) 

Source Link

Document

Returns a column key.

Usage

From source file:org.emftrace.quarc.ui.views.RatioView.java

/**
 * create a SpiderChart // ww  w . j  a v  a2s.c  o  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:org.pentaho.plugin.jfreereport.reportcharts.RadarChartExpression.java

private void initializeGrid(final DefaultCategoryDataset defaultDataset) {

    if (gridintervall < 0) {
        final double gridIntervalIncrement = -gridintervall;
        if ((100.0 / gridIntervalIncrement) > 5000) {
            return;
        }//from   w  w  w. j  a v  a  2  s  .  c  o m

        //insert the gridlines (fake data sets)
        double gridline = gridIntervalIncrement;
        final int columns = defaultDataset.getColumnCount();
        final double maxdata = computeMaxValue(defaultDataset);

        final NumberFormat format = NumberFormat
                .getPercentInstance(getRuntime().getResourceBundleFactory().getLocale());
        while (gridline <= 100) {
            final double gridScaled = maxdata * gridline / 100.0;
            final String gridLineText = format.format(gridline / 100.0);
            final GridCategoryItem rowKey = new GridCategoryItem(gridLineText);
            for (int i = 0; i < columns; i++) {
                defaultDataset.addValue(gridScaled, rowKey, defaultDataset.getColumnKey(i));
            }
            gridline = gridline + gridIntervalIncrement;
        }
    } else if (gridintervall > 0) {
        final int columns = defaultDataset.getColumnCount();
        final double maxdata = computeMaxValue(defaultDataset);
        final double gridIntervalIncrement = gridintervall;
        if ((maxdata / gridIntervalIncrement) > 5000) {
            return;
        }

        final NumberFormat format = NumberFormat
                .getNumberInstance(getRuntime().getResourceBundleFactory().getLocale());
        double gridline = 0;
        while (gridline < maxdata) {
            gridline = gridline + gridIntervalIncrement;
            final String gridLineText = format.format(gridline);
            final GridCategoryItem rowKey = new GridCategoryItem(gridLineText);
            for (int i = 0; i < columns; i++) {
                defaultDataset.addValue(gridline, rowKey, defaultDataset.getColumnKey(i));
            }
        }

    }
}

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  .  j  a  va  2 s  .  co 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$
        }
    } 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:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.WinLose.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createBarChart(name, null, null, dataset, PlotOrientation.VERTICAL, legend,
            false, false);/*from w  w  w.jav a2s.c om*/
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(color);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    plot.setRangeCrosshairPaint(color.BLACK);

    // customize axes 
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setCategoryMargin(0.2);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    rangeAxis.setRange(new Range(-(barHeight + 0.2), (barHeight + 0.2)));

    // customize renderer 
    MyBarRendererThresholdPaint renderer = new MyBarRendererThresholdPaint(useTargets, thresholds, dataset,
            timeSeries, nullValues, bottomThreshold, color);

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.#")) {
                    public String generateLabel(CategoryDataset dataset, int row, int column) {
                        if (dataset.getValue(row, column) == null
                                || dataset.getValue(row, column).doubleValue() == 0)
                            return "";
                        String columnKey = (String) dataset.getColumnKey(column);
                        int separator = columnKey.indexOf('-');
                        String month = columnKey.substring(0, separator);
                        String year = columnKey.substring(separator + 1);
                        int monthNum = Integer.parseInt(month);
                        if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                            if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                                return "";

                            Calendar calendar = Calendar.getInstance();
                            calendar.set(Calendar.MONTH, monthNum - 1);
                            SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                            return dataFormat.format(calendar.getTime());
                        } else
                            return "" + monthNum;
                    }
                });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4 || wlt_mode.doubleValue() == 5) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        plot.setFixedLegendItems(collection);
    }

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth);
    }
    //renderer.setSeriesPaint(0, Color.BLUE); 
    plot.setRenderer(renderer);

    logger.debug("OUT");
    if (mainThreshold == null)
        return null;
    return chart;

}