List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setBaseToolTipGenerator
public void setBaseToolTipGenerator(XYToolTipGenerator generator);
From source file:com.att.aro.ui.view.diagnostictab.plot.BluetoothPlot.java
@Override public void populate(XYPlot plot, AROTraceData analysis) { if (analysis != null) { bluetoothData.removeAllSeries(); XYIntervalSeries bluetoothConnected = new XYIntervalSeries(BluetoothState.BLUETOOTH_CONNECTED); XYIntervalSeries bluetoothDisconnected = new XYIntervalSeries(BluetoothState.BLUETOOTH_DISCONNECTED); XYIntervalSeries bluetoothOff = new XYIntervalSeries(BluetoothState.BLUETOOTH_TURNED_OFF); XYIntervalSeries bluetoothOn = new XYIntervalSeries(BluetoothState.BLUETOOTH_TURNED_ON); XYIntervalSeries bluetoothUnknown = new XYIntervalSeries(BluetoothState.BLUETOOTH_UNKNOWN); bluetoothData.addSeries(bluetoothConnected); bluetoothData.addSeries(bluetoothDisconnected); bluetoothData.addSeries(bluetoothOff); bluetoothData.addSeries(bluetoothOn); bluetoothData.addSeries(bluetoothUnknown); // Populate the data set Iterator<BluetoothInfo> iter = analysis.getAnalyzerResult().getTraceresult().getBluetoothInfos() .iterator();//from www .j a v a 2 s . com XYIntervalSeries series; if (iter.hasNext()) { while (iter.hasNext()) { BluetoothInfo btEvent = iter.next(); if (btEvent.getBluetoothState() == null) { series = bluetoothUnknown; } else { switch (btEvent.getBluetoothState()) { case BLUETOOTH_CONNECTED: series = bluetoothConnected; break; case BLUETOOTH_DISCONNECTED: series = bluetoothDisconnected; break; case BLUETOOTH_TURNED_ON: series = bluetoothOn; break; case BLUETOOTH_TURNED_OFF: series = bluetoothOff; break; default: series = bluetoothUnknown; break; } } series.add(btEvent.getBeginTimeStamp(), btEvent.getBeginTimeStamp(), btEvent.getEndTimeStamp(), 0.5, 0, 1); } } XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_CONNECTED), new Color(34, 177, 76)); renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_DISCONNECTED), Color.YELLOW); renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_TURNED_OFF), new Color(216, 132, 138)); renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_TURNED_ON), new Color(162, 226, 98)); renderer.setSeriesPaint(bluetoothData.indexOf(BluetoothState.BLUETOOTH_UNKNOWN), new Color(154, 154, 154)); // Assign ToolTip to renderer renderer.setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { BluetoothState eventType = (BluetoothState) bluetoothData.getSeries(series).getKey(); return MessageFormat.format(ResourceBundleHelper.getMessageString("bluetooth.tooltip"), dataset.getX(series, item), ResourceBundleHelper.getEnumString(eventType)); } }); } plot.setDataset(bluetoothData); // return plot; }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initTimeSeries(int datasetNumber, XYDataset dataset, SeriesDefinitionVO seriesDefinition) { IndicatorDefinitionVO indicatorDefinition = (IndicatorDefinitionVO) seriesDefinition; TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) dataset; // create the TimeSeries TimeSeries series = new TimeSeries(indicatorDefinition.getLabel()); timeSeriesCollection.addSeries(series); this.indicators.put(indicatorDefinition.getName(), series); // get the seriesNumber & color final int seriesNumber = timeSeriesCollection.getSeriesCount() - 1; // configure the renderer final XYItemRenderer renderer = getPlot().getRenderer(datasetNumber); renderer.setSeriesPaint(seriesNumber, getColor(indicatorDefinition.getColor())); renderer.setSeriesVisible(seriesNumber, seriesDefinition.isSelected()); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (seriesDefinition.isDashed()) { renderer.setSeriesStroke(seriesNumber, new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f)); } else {//from w ww. j a v a 2 s. com renderer.setSeriesStroke(seriesNumber, new BasicStroke(0.5f)); } // add the menu item JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel()); menuItem.setSelected(seriesDefinition.isSelected()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetAxis(); renderer.setSeriesVisible(seriesNumber, ((JCheckBoxMenuItem) e.getSource()).isSelected()); initAxis(); } }); this.getPopupMenu().add(menuItem); }
From source file:com.att.aro.ui.view.diagnostictab.plot.AlarmPlot.java
@Override public void populate(XYPlot plot, AROTraceData analysis) { if (analysis == null) { logger.info("analysis data is null"); } else {//w ww . j a v a 2 s . co m alarmDataCollection.removeAllSeries(); pointerAnnotation.clear(); TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType(); if (resultType.equals(TraceResultType.TRACE_FILE)) { logger.info("didn't get analysis trace data!"); } else { // Remove old annotation from previous plots Iterator<XYPointerAnnotation> pointers = pointerAnnotation.iterator(); while (pointers.hasNext()) { plot.removeAnnotation(pointers.next()); } for (AlarmType eventType : AlarmType.values()) { XYIntervalSeries series = new XYIntervalSeries(eventType); seriesMap.put(eventType, series); alarmDataCollection.addSeries(series); } TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult() .getTraceresult(); List<AlarmInfo> alarmInfos = traceresult.getAlarmInfos(); List<ScheduledAlarmInfo> pendingAlarms = getHasFiredAlarms(traceresult.getScheduledAlarms()); Iterator<ScheduledAlarmInfo> iterPendingAlarms = pendingAlarms.iterator(); double firedTime = 0; while (iterPendingAlarms.hasNext()) { ScheduledAlarmInfo scheduledEvent = iterPendingAlarms.next(); AlarmType pendingAlarmType = scheduledEvent.getAlarmType(); if (pendingAlarmType != null) { firedTime = (scheduledEvent.getTimeStamp() - scheduledEvent.getRepeatInterval()) / 1000; seriesMap.get(pendingAlarmType).add(firedTime, firedTime, firedTime, 1, 0.8, 1); eventMapPending.put(firedTime, scheduledEvent); // logger.fine("populateAlarmScheduledPlot type:\n" + // pendingAlarmType // + "\ntime " + scheduledEvent.getTimeStamp() // + "\nrepeating " + firedTime); } } Iterator<AlarmInfo> iter = alarmInfos.iterator(); while (iter.hasNext()) { AlarmInfo currEvent = iter.next(); if (currEvent != null) { AlarmType alarmType = currEvent.getAlarmType(); if (alarmType != null) { firedTime = currEvent.getTimeStamp() / 1000; /* * Catching any alarms align to quanta as being * inexactRepeating alarms */ if ((currEvent.getTimestampElapsed() / 1000) % 900 < 1) { seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.7); // Adding an arrow to mark these // inexactRepeating alarms XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(alarmType.name(), firedTime, 0.6, 3.92699082D); xypointerannotation.setBaseRadius(20D); xypointerannotation.setTipRadius(1D); pointerAnnotation.add(xypointerannotation); plot.addAnnotation(xypointerannotation); // logger.info("SetInexactRepeating alarm type: " // + alarmType // + " time " + firedTime // + " epoch " + currEvent.getTimestampEpoch() // + " elapsed:\n" + // currEvent.getTimestampElapsed()/1000); } else { seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.5); } eventMap.put(firedTime, currEvent); } } } XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC_WAKEUP), Color.red); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC), Color.pink); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME_WAKEUP), Color.blue); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME), Color.cyan); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.UNKNOWN), Color.black); // Assign ToolTip to renderer renderer.setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { AlarmInfo info = eventMap.get(dataset.getX(series, item)); Date epochTime = new Date(); if (info != null) { epochTime.setTime((long) info.getTimestampEpoch()); StringBuffer displayInfo = new StringBuffer( ResourceBundleHelper.getMessageString("alarm.tooltip.prefix")); displayInfo.append(MessageFormat.format( ResourceBundleHelper.getMessageString("alarm.tooltip.content"), info.getAlarmType(), info.getTimeStamp() / 1000, epochTime.toString())); if ((info.getTimestampElapsed() / 1000) % 900 < 1) { displayInfo.append( ResourceBundleHelper.getMessageString("alarm.tooltip.setInexactRepeating")); } displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix")); return displayInfo.toString(); } ScheduledAlarmInfo infoPending = eventMapPending.get(dataset.getX(series, item)); if (infoPending != null) { epochTime.setTime( (long) (infoPending.getTimestampEpoch() - infoPending.getRepeatInterval())); StringBuffer displayInfo = new StringBuffer( ResourceBundleHelper.getMessageString("alarm.tooltip.prefix")); displayInfo.append(MessageFormat.format( ResourceBundleHelper.getMessageString("alarm.tooltip.contentWithName"), infoPending.getAlarmType(), (infoPending.getTimeStamp() - infoPending.getRepeatInterval()) / 1000, epochTime.toString(), infoPending.getApplication(), infoPending.getRepeatInterval() / 1000)); displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix")); return displayInfo.toString(); } return null; } }); } } plot.setDataset(alarmDataCollection); // return plot; }
From source file:net.sf.clichart.chart.AbstractChartBuilder.java
private void setAxisRenderer(XYPlot plot, int axisIndex, boolean isBarChart, boolean hasDataPoints, int lineWeight) { XYItemRenderer renderer; if (isBarChart) { renderer = new ClusteredXYBarRenderer(); XYDataset axisDataset = plot.getDataset(axisIndex); plot.setDataset(axisIndex, new XYBarDataset(axisDataset, calculateBarWidth(axisDataset, lineWeight))); } else {/*from w w w . j ava2s.com*/ renderer = new XYLineAndShapeRenderer(true, hasDataPoints); if (lineWeight >= 0 && lineWeight <= 5) { for (int seriesIndex = 0; seriesIndex < plot.getDataset(axisIndex) .getSeriesCount(); seriesIndex++) { renderer.setSeriesStroke(seriesIndex, new BasicStroke((float) lineWeight)); } } } renderer.setBaseToolTipGenerator(getToolTipGenerator()); plot.setRenderer(axisIndex, renderer); }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a scatter plot with default settings. The chart object * returned by this method uses an {@link XYPlot} instance as the plot, * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} * as the range axis, and an {@link XYLineAndShapeRenderer} as the * renderer. //from w w w . jav a 2 s . co m * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A scatter plot. */ public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a histogram chart. This chart is constructed with an * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range * axes are {@link NumberAxis} instances. * /* w w w . jav a2s. c o m*/ * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel the x axis label (<code>null</code> permitted). * @param yAxisLabel the y axis label (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend create a legend? * @param tooltips display tooltips? * @param urls generate URLs? * * @return The chart. */ public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); ValueAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);//from ww w .j a va 2 s .c o m plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.75f); // 2. Setup Scatter plot // Create the bubble chart data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator()); plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plotRenderer .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // Set the bubble chart data, renderer, and axis into plot plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED); plot.setDataset(2, new DefaultXYZDataset2()); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:eu.hydrologis.jgrass.charting.datamodels.MultiXYTimeChartCreator.java
/** * Make a composite with the plot of the supplied chartdata. There are several HINT* variables * that can be set to tweak and configure the plot. * /*from w w w.j a va 2s . com*/ * @param parentComposite * @param chartData */ public void makePlot(Composite parentComposite, NumericChartData chartData) { final int tabNums = chartData.getTabItemNumbers(); if (tabNums == 0) { return; } Shell dummyShell = null; // try { // dummyShell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); // } catch (Exception e) { dummyShell = new Shell(Display.getCurrent(), SWT.None); // } /* * wrapping panel needed in the case of hide checks */ TabFolder tabFolder = null; if (tabNums > 1) { tabFolder = new TabFolder(parentComposite, SWT.BORDER); tabFolder.setLayout(new GridLayout()); tabFolder.setLayoutData( new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); } for (int i = 0; i < tabNums; i++) { NumericChartDataItem chartItem = chartData.getChartDataItem(i); int chartNums = chartItem.chartSeriesData.size(); /* * are there data to create the lower chart panel */ List<LinkedHashMap<String, Integer>> series = new ArrayList<LinkedHashMap<String, Integer>>(); List<XYPlot> plots = new ArrayList<XYPlot>(); List<JFreeChart> charts = new ArrayList<JFreeChart>(); for (int j = 0; j < chartNums; j++) { final LinkedHashMap<String, Integer> chartSeries = new LinkedHashMap<String, Integer>(); XYPlot chartPlot = null; JGrassChart chart = null; double[][][] cLD = chartItem.chartSeriesData.get(j); if (M_HINT_CREATE_CHART[i][j]) { final String[] cT = chartItem.seriesNames.get(j); final String title = chartItem.chartTitles.get(j); final String xT = chartItem.chartXLabels.get(j); final String yT = chartItem.chartYLabels.get(j); if (M_HINT_CHART_TYPE[i][j] == XYLINECHART) { chart = new JGrassXYLineChart(cT, cLD); } else if (M_HINT_CHART_TYPE[i][j] == XYBARCHART) { chart = new JGrassXYBarChart(cT, cLD, HINT_barwidth); } else if (M_HINT_CHART_TYPE[i][j] == TIMEYLINECHART) { chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class); ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT); } else if (M_HINT_CHART_TYPE[i][j] == TIMEYBARCHART) { chart = new JGrassXYTimeBarChart(cT, cLD, Minute.class, HINT_barwidth); ((JGrassXYTimeBarChart) chart).setTimeAxisFormat(TIMEFORMAT); } else if (M_HINT_CHART_TYPE[i][j] == XYPOINTCHART) { chart = new JGrassXYLineChart(cT, cLD); ((JGrassXYLineChart) chart).toggleLineShapesDisplay(false, true); } else if (M_HINT_CHART_TYPE[i][j] == TIMEXYPOINTCHART) { chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class); ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT); ((JGrassXYTimeLineChart) chart).toggleLineShapesDisplay(false, true); } else { chart = new JGrassXYLineChart(cT, cLD); } final Composite p1Composite = new Composite(dummyShell, SWT.None); p1Composite.setLayout(new FillLayout()); p1Composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); chart.makeChartPanel(p1Composite, title, xT, yT, null, true, true, true, true); chartPlot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = chartPlot.getRenderer(); chartPlot.setDomainGridlinesVisible(HINT_doDomainGridVisible); chartPlot.setRangeGridlinesVisible(HINT_doRangeGridVisible); if (HINT_doDisplayToolTips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (!M_HINT_CHARTORIENTATION_UP[i][j]) { chartPlot.getRangeAxis().setInverted(true); } if (M_HINT_CHARTSERIESCOLOR != null) { final XYItemRenderer rend = renderer; for (int k = 0; k < cLD.length; k++) { rend.setSeriesPaint(k, M_HINT_CHARTSERIESCOLOR[i][j][k]); } } chart.toggleFilledShapeDisplay(HINT_doDisplayBaseShapes, HINT_doFillBaseShapes, true); for (int k = 0; k < cT.length; k++) { chartSeries.put(cT[k], k); } series.add(chartSeries); chartPlot.setNoDataMessage("No data available"); chartPlot.setNoDataMessagePaint(Color.red); plots.add(chartPlot); charts.add(chart.getChart(title, xT, yT, null, true, HINT_doDisplayToolTips, true)); chartsList.add(chart); /* * add annotations? */ if (chartItem.annotationsOnChart.size() > 0) { LinkedHashMap<String, double[]> annotations = chartItem.annotationsOnChart.get(j); if (annotations.size() > 0) { Set<String> keys = annotations.keySet(); for (String key : keys) { double[] c = annotations.get(key); XYPointerAnnotation ann = new XYPointerAnnotation(key, c[0], c[1], HINT_AnnotationArrowAngle); ann.setTextAnchor(HINT_AnnotationTextAncor); ann.setPaint(HINT_AnnotationTextColor); ann.setArrowPaint(HINT_AnnotationArrowColor); // ann.setArrowLength(15); renderer.addAnnotation(ann); // Marker currentEnd = new ValueMarker(c[0]); // currentEnd.setPaint(Color.red); // currentEnd.setLabel(""); // currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); // currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); // chartPlot.addDomainMarker(currentEnd); // Drawable cd = new LineDrawer(Color.red, new BasicStroke(1.0f)); // XYAnnotation bestBid = new XYDrawableAnnotation(c[0], c[1]/2.0, // 0, c[1], // cd); // chartPlot.addAnnotation(bestBid); // pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); } } } } } JFreeChart theChart = null; if (plots.size() > 1) { ValueAxis domainAxis = null; if (M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYBARCHART || M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYLINECHART) { domainAxis = (plots.get(0)).getDomainAxis(); } else { domainAxis = new NumberAxis(chartItem.chartXLabels.get(0)); } final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis); plot.setGap(10.0); // add the subplots... for (int k = 0; k < plots.size(); k++) { XYPlot tmpPlot = plots.get(k); if (HINT_labelInsets != null) { tmpPlot.getRangeAxis().setLabelInsets(HINT_labelInsets); } plot.add(tmpPlot, k + 1); } plot.setOrientation(PlotOrientation.VERTICAL); theChart = new JFreeChart(chartItem.bigTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else if (plots.size() == 1) { theChart = new JFreeChart(chartItem.chartTitles.get(0), JFreeChart.DEFAULT_TITLE_FONT, plots.get(0), true); } else { return; } /* * create the chart composite */ Composite tmp; if (tabNums > 1 && tabFolder != null) { tmp = new Composite(tabFolder, SWT.None); } else { tmp = new Composite(parentComposite, SWT.None); } tmp.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); tmp.setLayout(new GridLayout()); final ChartComposite frame = new ChartComposite(tmp, SWT.None, theChart, 680, 420, 300, 200, 700, 500, false, true, // properties true, // save true, // print true, // zoom true // tooltips ); // public static final boolean DEFAULT_BUFFER_USED = false; // public static final int DEFAULT_WIDTH = 680; // public static final int DEFAULT_HEIGHT = 420; // public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300; // public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200; // public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800; // public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600; // public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10; frame.setLayoutData( new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); frame.setLayout(new FillLayout()); frame.setDisplayToolTips(HINT_doDisplayToolTips); frame.setHorizontalAxisTrace(HINT_doHorizontalAxisTrace); frame.setVerticalAxisTrace(HINT_doVerticalAxisTrace); frame.setDomainZoomable(HINT_doDomainZoomable); frame.setRangeZoomable(HINT_doRangeZoomable); if (tabNums > 1 && tabFolder != null) { final TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText(chartData.getChartDataItem(i).chartStringExtra); item.setControl(tmp); } /* * create the hide toggling part */ for (int j = 0; j < plots.size(); j++) { if (M_HINT_CREATE_TOGGLEHIDESERIES[i][j]) { final LinkedHashMap<Button, Integer> allButtons = new LinkedHashMap<Button, Integer>(); Group checksComposite = new Group(tmp, SWT.None); checksComposite.setText(""); RowLayout rowLayout = new RowLayout(); rowLayout.wrap = true; rowLayout.type = SWT.HORIZONTAL; checksComposite.setLayout(rowLayout); checksComposite .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); final XYItemRenderer renderer = plots.get(j).getRenderer(); Set<String> lTitles = series.get(j).keySet(); for (final String title : lTitles) { final Button b = new Button(checksComposite, SWT.CHECK); b.setText(title); b.setSelection(true); final int index = series.get(j).get(title); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { boolean visible = renderer.getItemVisible(index, 0); renderer.setSeriesVisible(index, new Boolean(!visible)); } }); allButtons.put(b, index); } /* * toggle all and none */ if (HINT_doToggleTuttiButton) { Composite allchecksComposite = new Composite(tmp, SWT.None); RowLayout allrowLayout = new RowLayout(); allrowLayout.wrap = true; allrowLayout.type = SWT.HORIZONTAL; allchecksComposite.setLayout(allrowLayout); allchecksComposite .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); final Button tuttiButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH); tuttiButton.setText("Tutti"); tuttiButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Set<Button> set = allButtons.keySet(); for (Button button : set) { button.setSelection(true); int i = allButtons.get(button); if (renderer != null) { renderer.setSeriesVisible(i, new Boolean(true)); } } } }); final Button noneButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH); noneButton.setText("Nessuno"); noneButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Set<Button> set = allButtons.keySet(); for (Button button : set) { button.setSelection(false); int i = allButtons.get(button); if (renderer != null) { renderer.setSeriesVisible(i, new Boolean(false)); } } } }); } } } } }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items. /* w w w .j av a 2 s .co m*/ * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a scatter plot with default settings. The chart object * returned by this method uses an {@link XYPlot} instance as the plot, * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} * as the range axis, and an {@link XYLineAndShapeRenderer} as the * renderer./*from www . j ava2 s .co m*/ * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A scatter plot. */ public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }