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

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

Introduction

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

Prototype

@Override
public Comparable getRowKey(int row) 

Source Link

Document

Returns the key for the specified row.

Usage

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

/**
 * create a SpiderChart // ww  w  . ja  v a 2 s . c  om
 * @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.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.c  o 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:org.leo.benchmark.Benchmark.java

/**
 * Create a chartpanel/*from   w  w w . j  a  va  2  s .  co  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;
}