Example usage for org.jfree.data.xy XYDataset getSeriesKey

List of usage examples for org.jfree.data.xy XYDataset getSeriesKey

Introduction

In this page you can find the example usage for org.jfree.data.xy XYDataset getSeriesKey.

Prototype

public Comparable getSeriesKey(int series);

Source Link

Document

Returns the key for a series.

Usage

From source file:org.jfree.chart.demo.MouseListenerDemo3.java

public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
    org.jfree.chart.entity.ChartEntity chartentity = chartmouseevent.getEntity();
    if (chartentity != null && (chartentity instanceof LegendItemEntity)) {
        LegendItemEntity legenditementity = (LegendItemEntity) chartentity;
        @SuppressWarnings("rawtypes")
        Comparable comparable = legenditementity.getSeriesKey();
        XYPlot xyplot = (XYPlot) chart.getPlot();
        XYDataset xydataset = xyplot.getDataset();
        XYItemRenderer xyitemrenderer = xyplot.getRenderer();
        for (int i = 0; i < xydataset.getSeriesCount(); i++) {
            xyitemrenderer.setSeriesStroke(i, new BasicStroke(1.0F));
            if (xydataset.getSeriesKey(i).equals(comparable))
                xyitemrenderer.setSeriesStroke(i, new BasicStroke(2.0F));
        }//www.j  a v  a 2  s  .  c o  m

    }
}

From source file:net.sf.dynamicreports.test.jasper.chart.ChartSeriesColorsByNameTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*  www  . j a  va2 s. c om*/

    chartCountTest("summary.chart1", 1);
    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryItemRenderer renderer1 = chart.getCategoryPlot().getRenderer();
    CategoryDataset dataset1 = chart.getCategoryPlot().getDataset();
    for (int i = 0; i < dataset1.getRowCount(); i++) {
        String key = (String) dataset1.getRowKey(i);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), renderer1.getSeriesPaint(i));
    }

    chartCountTest("summary.chart2", 1);
    chart = getChart("summary.chart2", 0);
    CategoryItemRenderer renderer2 = chart.getCategoryPlot().getRenderer();
    CategoryDataset dataset2 = chart.getCategoryPlot().getDataset();
    for (int i = 0; i < dataset2.getRowCount(); i++) {
        String key = (String) dataset2.getRowKey(i);
        key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), renderer2.getSeriesPaint(i));
    }
    for (int i = 0; i < chart.getCategoryPlot().getFixedLegendItems().getItemCount(); i++) {
        LegendItem legendItem = chart.getCategoryPlot().getFixedLegendItems().get(i);
        Assert.assertNotNull("null series color", colors.get(legendItem.getLabel()));
        Assert.assertEquals("series color", colors.get(legendItem.getLabel()), legendItem.getFillPaint());
    }

    chartCountTest("summary.chart3", 1);
    chart = getChart("summary.chart3", 0);
    PiePlot plot3 = (PiePlot) chart.getPlot();
    PieDataset dataset3 = plot3.getDataset();
    for (int i = 0; i < dataset3.getItemCount(); i++) {
        String key = (String) dataset3.getKey(i);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), plot3.getSectionPaint(key));
    }

    chartCountTest("summary.chart4", 1);
    chart = getChart("summary.chart4", 0);
    XYItemRenderer renderer4 = chart.getXYPlot().getRenderer();
    XYDataset dataset4 = chart.getXYPlot().getDataset();
    for (int i = 0; i < dataset4.getSeriesCount(); i++) {
        String key = (String) dataset4.getSeriesKey(i);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), renderer4.getSeriesPaint(i));
    }
}

From source file:org.pentaho.platform.uifoundation.chart.PentahoChartURLTagFragmentGenerator.java

@Override
public String generateURLFragment(final String urlText) {
    if (urlFragment != null) {

        String urlTemplate = " href=\""; //$NON-NLS-1$

        // do not add ase URL if script
        boolean isScript = urlFragment.startsWith("javascript:"); //$NON-NLS-1$ 

        // If isScript is true, ignore useBaseURL parameter...
        if (!isScript) {
            if (useBaseUrl) {
                urlTemplate += PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
            }//  w w w  .j  ava2  s.  c o m
        }

        // Handle " in the urlFragment
        urlTemplate += urlFragment.replaceAll("\"", "%22") + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 

        String value = null;
        String itemValue = null;

        // Do we have a 'category=' as part of the urlText in? If so, grab the value from the urlText
        // this is the replacement value for the paramName parameter (when categorical).
        value = retrieveValue(PentahoChartURLTagFragmentGenerator.CATEGORY_TAG, urlText);

        if (value != null) {
            urlTemplate = TemplateUtil.applyTemplate(urlTemplate, parameterName, value); // <paramName> replacement
                                                                                         // value
        }

        // Do we have a 'series=' as part of the urlText in? If so, grab the value from the urlText
        // this is the replacement value for the series-name parameter.
        value = retrieveValue(PentahoChartURLTagFragmentGenerator.SERIES_TAG, urlText);
        if (value != null) {

            if ((dataset instanceof CategoryDatasetChartDefinition)
                    || (dataset instanceof XYZSeriesCollectionChartDefinition)) {

                urlTemplate = TemplateUtil.applyTemplate(urlTemplate, seriesName, value); // <series-name> replacement
                                                                                          // value

            } else if (dataset instanceof XYDataset) {

                XYDataset set = (XYDataset) dataset;
                Comparable<?> seriesKey = set.getSeriesKey(Integer.parseInt(value));
                urlTemplate = TemplateUtil.applyTemplate(urlTemplate, seriesName, seriesKey.toString()); // <series-name>
                                                                                                         // replacement
                                                                                                         // value

                // Do we have an 'item=' as part of the urlText in? If so, grab the value from the urlText
                // this is the replacement value for the paramName parameter, when the chart is an x/y plot.
                itemValue = retrieveValue(PentahoChartURLTagFragmentGenerator.ITEM_TAG, urlText);

                if (itemValue != null) {

                    int itemVal = Integer.parseInt(itemValue);
                    int val = Integer.parseInt(value);

                    Object x = null;
                    Number xNum = set.getX(val, itemVal);
                    x = (xNum instanceof Long) ? new Date((Long) xNum) : xNum;

                    urlTemplate = TemplateUtil.applyTemplate(urlTemplate, parameterName, x.toString()); // <paramName>
                                                                                                        // replacement
                                                                                                        // value

                    // This value is NEW. We have never returned more than 2 parameters in the url-template.
                    // A logical extension for x/y plots is to return the series, the x value and the y value.
                    // However, the item value is not plumbed through to the chart definition yet.
                    Object y = null;
                    Number yNum = set.getY(val, itemVal);
                    y = (yNum instanceof Long) ? new Date((Long) yNum) : yNum;

                    urlTemplate = TemplateUtil.applyTemplate(urlTemplate, "ITEM", y.toString()); // {ITEM} replacement
                                                                                                 // value,
                                                                                                 // in the
                                                                                                 // url-template. There
                                                                                                 // is no
                                                                                                 // parameter
                                                                                                 // plumbed for this.
                }
            }
        }

        if (!isScript) {
            urlTemplate = urlTemplate + " target=\"" + urlTarget + "\""; //$NON-NLS-1$//$NON-NLS-2$ 
        }

        return urlTemplate;
    } else {
        return super.generateURLFragment(urlText);
    }
}

From source file:com.att.aro.ui.view.diagnostictab.plot.CameraPlot.java

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    XYIntervalSeriesCollection cameraData = new XYIntervalSeriesCollection();

    if (analysis != null) {

        XYIntervalSeries series = new XYIntervalSeries(CameraState.CAMERA_ON);
        cameraData.addSeries(series);/*from  w  w w . j a va 2 s  . co  m*/

        // Populate the data set
        Iterator<CameraInfo> iter = analysis.getAnalyzerResult().getTraceresult().getCameraInfos().iterator();
        if (iter.hasNext()) {
            while (iter.hasNext()) {
                CameraInfo cameraEvent = iter.next();
                if (cameraEvent.getCameraState() == CameraState.CAMERA_ON) {
                    series.add(cameraEvent.getBeginTimeStamp(), cameraEvent.getBeginTimeStamp(),
                            cameraEvent.getEndTimeStamp(), 0.5, 0, 1);
                }
            }
        }

        // Assign ToolTip to renderer
        XYItemRenderer renderer = plot.getRenderer();
        renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {
                return MessageFormat.format(ResourceBundleHelper.getMessageString("camera.tooltip"),
                        dataset.getX(series, item),
                        ResourceBundleHelper.getEnumString((Enum<?>) dataset.getSeriesKey(series)));
            }
        });

    }

    plot.setDataset(cameraData);
    //      return plot;
}

From source file:org.talend.dataprofiler.chart.util.HideSeriesChartDialog.java

private Composite createUtilityControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.BORDER);
    comp.setLayout(new RowLayout());
    comp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    if (isCountAvgNull) {
        XYDataset dataset = chart.getXYPlot().getDataset();
        int count = dataset.getSeriesCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getSeriesKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }/*from  ww  w . j a  v  a2s.  c  o  m*/
    }

    if (isMinMaxDate) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryDataset dataset = plot.getDataset();
        int count = dataset.getRowCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getRowKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }
    }

    return comp;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaXYZURLGenerator.java

/**
 * Generates a URL for a particular item within a series.
 *
 * @param dataset the dataset./*from w w  w . ja v a  2s  .  co  m*/
 * @param series  the series number (zero-based index).
 * @param item    the item number (zero-based index).
 * @return The generated URL.
 */
public String generateURL(final XYDataset dataset, final int series, final int item) {
    if (dataset instanceof XYZDataset) {
        return generateURL((XYZDataset) dataset, series, item);
    }
    try {
        final Object[] values = new Object[] { dataset.getX(series, item), dataset.getY(series, item), null,
                IntegerCache.getInteger(series), dataset.getSeriesKey(series),
                IntegerCache.getInteger(dataset.getSeriesCount()), IntegerCache.getInteger(item),
                IntegerCache.getInteger(dataset.getItemCount(series)) };
        formulaExpression.setRuntime(
                new WrapperExpressionRuntime(new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values), runtime));
        final Object o = formulaExpression.getValue();
        if (o == null) {
            return null;
        }
        return String.valueOf(o);
    } finally {
        formulaExpression.setRuntime(null);
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaXYZTooltipGenerator.java

/**
 * Generates the tooltip text for the specified item.
 *
 * @param dataset the dataset (<code>null</code> not permitted).
 * @param series  the series index (zero-based).
 * @param item    the item index (zero-based).
 * @return The tooltip text (possibly <code>null</code>).
 *///from   w ww  .  ja  v  a2s .com
public String generateToolTip(final XYDataset dataset, final int series, final int item) {
    if (dataset instanceof XYZDataset) {
        return generateToolTip((XYZDataset) dataset, series, item);
    }
    try {
        final Object[] values = new Object[] { dataset.getX(series, item), dataset.getY(series, item), null,
                IntegerCache.getInteger(series), dataset.getSeriesKey(series),
                IntegerCache.getInteger(dataset.getSeriesCount()), IntegerCache.getInteger(item),
                IntegerCache.getInteger(dataset.getItemCount(series)) };
        formulaExpression.setRuntime(
                new WrapperExpressionRuntime(new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values), runtime));
        final Object o = formulaExpression.getValue();
        if (o == null) {
            return null;
        }
        return String.valueOf(o);
    } finally {
        formulaExpression.setRuntime(null);
    }
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java

@Override
public void chartProgress(ChartProgressEvent event) {
    if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) {
        return;/*  www .j ava 2s. c o m*/
    }

    // update the table model

    if (this.chartPanel != null) {
        JFreeChart c = this.getChart();
        if (c != null) {
            XYPlot plot = (XYPlot) c.getPlot();

            int ndex = this.getCrossHairDomainIndex();

            // update the table from the value at the crosshair

            for (int pnum = 0; pnum < NumDataSets; pnum++) {
                XYDataset dataset = plot.getDataset(pnum);
                String seriesName = "Unknown";
                if ((dataset != null) && (dataset.getSeriesKey(0) != null)) {
                    int ds_size = dataset.getItemCount(0);
                    if (dataset.getSeriesKey(0) instanceof String)
                        seriesName = (String) dataset.getSeriesKey(0);

                    // the name
                    this.model.setValueAt(seriesName, pnum, 0);

                    // the deltas are one smaller than the counters, so make sure the
                    // crosshair index is valid
                    if (ndex < ds_size) {
                        // the time
                        this.model.setValueAt(dataset.getXValue(0, ndex), pnum, 1);

                        // the value
                        this.model.setValueAt(dataset.getYValue(0, ndex), pnum, 2);
                    }

                    // the units (key off the series name)
                    PortCounterAxisLabel label = PortCounterAxisLabel.getByName(seriesName);
                    if (label != null)
                        this.model.setValueAt(label.getUnits(), pnum, 3);
                    else
                        this.model.setValueAt(PortCounterAxisLabel.DELTA.getUnits(), pnum, 3);
                }
            }
        } else
            System.err.println("Its NULL, Jim!");
    }
}

From source file:MWC.GUI.JFreeChart.ColourStandardXYItemRenderer.java

/**
 * Returns a legend item for a series.//  w  ww.  j  a  v  a 2 s  .c  om
 * 
 * @param series
 *          the series (zero-based index).
 * 
 * @return a legend item for the series.
 */
public LegendItem getLegendItem(final int series) {

    final XYPlot plot = this.getPlot();

    final XYDataset dataset = plot.getDataset();
    final String label = (String) dataset.getSeriesKey(series);
    final String description = label;
    final Shape shape = null;
    final Paint paint = this.getSeriesPaint(series);
    final Paint outlinePaint = paint;
    final Stroke stroke = plot.getRenderer().getSeriesStroke(series);

    return new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint);
}

From source file:tdunnick.jphineas.console.queue.Charts.java

private JFreeChart createLineChart(String title, String constraint, XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(title, "Date/Time", // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from   w  ww. j a v a 2s . c  o  m
    XYPlot plot = chart.getXYPlot();
    // X axis shows dates
    plot.setDomainAxis(new DateAxis());
    // if data has a constraint, hide every thing else
    if (constraint != null) {
        chart.removeLegend();
        XYDataset data = plot.getDataset();
        Paint bg = plot.getBackgroundPaint();
        for (int i = 0; i < data.getSeriesCount(); i++) {
            if (!constraint.equals(data.getSeriesKey(i)))
                plot.getRenderer().setSeriesPaint(i, bg);
            else {
                // get a color match...
                plot.getRenderer().setSeriesPaint(i, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i]);
                // reset plot range for this maximum
                double d = 0;
                for (int j = 0; j < data.getItemCount(i); j++) {
                    if (d < data.getYValue(i, j))
                        d = data.getYValue(i, j);
                }
                // add a bit for top margin
                d += d * 0.04;
                plot.getRangeAxis().setUpperBound(d);
            }
        }
    }
    return chart;
}