List of usage examples for org.jfree.data UnknownKeyException printStackTrace
public void printStackTrace()
From source file:controletanquesproj1.Grafico.java
public void updatePoint(ArrayList[] vetorDeItensDeGrafico) { for (int k = 0; k < vetorDeItensDeGrafico.length; k++) { for (int i = 0; i < vetorDeItensDeGrafico[k].size(); i++) { ItemDeGrafico itemDeGrafico = (ItemDeGrafico) vetorDeItensDeGrafico[k].get(i); try { serie = getDatasets()[k].getSeries(itemDeGrafico.getNome());//Sempre d erro } catch (UnknownKeyException ex) { ex.printStackTrace(); }/*from w ww .j a v a 2s . co m*/ serie.remove(0); serie.addOrUpdate(serie.getMaxX() + 1, itemDeGrafico.getUltimoPonto().getY()); } } }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java
/*********************************************************************************************** * Update those items on the Chart which are taken from the DAO Metadata, * i.e./*from ww w.j a va2 s . c om*/ * Title * Axis.X * Axis.Y.0 * Series Keys (from Channel.Name) * Channel.Colour * * @param chartui * @param dao * @param channelselector * @param debug */ private static void updateChartFromDAOMetadata(final ChartUIComponentPlugin chartui, final ObservatoryInstrumentDAOInterface dao, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final String SOURCE = "ChartHelper.updateChartFromDAOMetadata() "; if ((chartui != null) && (chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null) && (dao != null) && (dao.getXYDataset() != null) && (dao.getObservationMetadata() != null) && (channelselector != null)) { // The set of Metadata available should include the Instrument // and any items from the current observation MetadataHelper.showDAOMetadata(dao, SOURCE, debug); if (chartui.getChartPanel().getChart().getTitle() != null) { final String strTitle; // Update Title strTitle = MetadataHelper.getMetadataValueByKey(dao.getObservationMetadata(), MetadataDictionary.KEY_OBSERVATION_TITLE.getKey()); chartui.getChartPanel().getChart().getTitle().setText(strTitle); LOGGER.debug(debug, SOURCE + "Set new Chart Title [title=" + strTitle + "]"); } else { LOGGER.error(SOURCE + "Chart Title is NULL"); } if (chartui.getChartPanel().getChart().getXYPlot() != null) { final String strLabelX; final String strLabelY; final XYItemRenderer renderer; // Update Axis labels strLabelX = MetadataHelper.getMetadataValueByKey(dao.getObservationMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_X.getKey()); // Axis.Y.0 only in this version strLabelY = MetadataHelper.getMetadataValueByKey(dao.getObservationMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO); // Assume the axes are not NULL chartui.getChartPanel().getChart().getXYPlot().getDomainAxis().setLabel(strLabelX); chartui.getChartPanel().getChart().getXYPlot().getRangeAxis().setLabel(strLabelY); //--------------------------------------------------------------------------------- // Re-synchronise the ChannelNames with the Series Keys, in case of edits if ((DatasetType.XY.equals(chartui.getDatasetType())) && (dao.getXYDataset() instanceof XYSeriesCollection)) { try { final List<XYSeries> listXYSeries; // JFreeChart doesn't do Generics! listXYSeries = ((XYSeriesCollection) dao.getXYDataset()).getSeries(); for (int intSeriesIndex = 0; intSeriesIndex < listXYSeries.size(); intSeriesIndex++) { final XYSeries xySeries; final String strChannelName; xySeries = listXYSeries.get(intSeriesIndex); // Get the channel names from the ObservationMetadata strChannelName = MetadataHelper.getChannelName(dao.getObservationMetadata(), intSeriesIndex, dao.hasTemperatureChannel()); // Set the Series Key to be the same as the Channel.Name // This will appear on the Chart Legend LOGGER.debug(debug, SOURCE + "Set XY Series Key [series.index=" + intSeriesIndex + "] [key=" + strChannelName + "]"); xySeries.setKey(strChannelName); } } catch (final UnknownKeyException exception) { LOGGER.error(SOURCE + "XYSeries has an unknown key"); exception.printStackTrace(); } } else if ((DatasetType.TIMESTAMPED.equals(chartui.getDatasetType())) && (dao.getXYDataset() instanceof TimeSeriesCollection)) { try { final List<TimeSeries> listTimeSeries; // JFreeChart doesn't do Generics! listTimeSeries = ((TimeSeriesCollection) dao.getXYDataset()).getSeries(); for (int intSeriesIndex = 0; intSeriesIndex < listTimeSeries.size(); intSeriesIndex++) { final TimeSeries timeSeries; final String strChannelName; timeSeries = listTimeSeries.get(intSeriesIndex); // Get the channel names from the ObservationMetadata strChannelName = MetadataHelper.getChannelName(dao.getObservationMetadata(), intSeriesIndex, dao.hasTemperatureChannel()); // Set the Series Key to be the same as the Channel.Name // This will appear on the Chart Legend LOGGER.debug(debug, SOURCE + "Set TIMESTAMPED Series Key [series.index=" + intSeriesIndex + "] [key=" + strChannelName + "]"); timeSeries.setKey(strChannelName); } } catch (final UnknownKeyException exception) { LOGGER.error(SOURCE + "TimeSeries has an unknown key"); exception.printStackTrace(); } } else { LOGGER.error(SOURCE + "Unexpected Chart DatasetType [type=" + chartui.getDatasetType() + "]"); } //--------------------------------------------------------------------------------- // Update ChannelColours renderer = chartui.getChartPanel().getChart().getXYPlot().getRenderer(); if ((renderer != null) && (renderer instanceof XYLineAndShapeRenderer)) { final XYLineAndShapeRenderer xyItemRenderer; int intSeriesCount; xyItemRenderer = (XYLineAndShapeRenderer) renderer; // Colour only as many Series as we know about intSeriesCount = 0; // Examine the state of each channel's selection // Chart updates occur last, so we can use any changes in the ChannelSelector state for (int intChannelIndex = 0; intChannelIndex < channelselector .getChannelCount(); intChannelIndex++) { final ChannelSelectionMode selectionMode; if ((channelselector.getChannelSelectionModes() != null) && (channelselector .getChannelSelectionModes().size() == channelselector.getChannelCount())) { // If there is a ChannelSelector, get the gain setting, or OFF selectionMode = channelselector.getChannelSelectionModes().get(intChannelIndex); } else if (!channelselector.showChannels()) { // If there is no ChannelSelector, we assume that all Channels are ON, at X1 selectionMode = ChannelSelectionMode.X1; } else { // Not sure what to do, so just show all selectionMode = ChannelSelectionMode.X1; } // Colour all visible channels if (!ChannelSelectionMode.OFF.equals(selectionMode)) { final ColourInterface colour; colour = MetadataHelper.getChannelColour(dao.getObservationMetadata(), intChannelIndex, channelselector.hasTemperatureChannel()); if (colour != null) { // Map the Colour to the Series xyItemRenderer.setSeriesPaint(intSeriesCount, colour.getColor()); } else { // Use the default colour if the metadata doesn't have it LOGGER.error(SOURCE + "The channel colour was missing or incorrectly specified in the Metadata, using default colour" + " [channel=" + intChannelIndex + "]"); xyItemRenderer.setSeriesPaint(intSeriesCount, ChartUIHelper.getStandardColour(intChannelIndex).getColor()); } // Prepare for the next Series intSeriesCount++; } } } } chartui.getChartPanel().getChart().fireChartChanged(); } else { LOGGER.error(SOURCE + "Unable to update Chart"); } }