List of usage examples for org.jfree.chart.labels StandardXYToolTipGenerator DEFAULT_TOOL_TIP_FORMAT
String DEFAULT_TOOL_TIP_FORMAT
To view the source code for org.jfree.chart.labels StandardXYToolTipGenerator DEFAULT_TOOL_TIP_FORMAT.
Click Source Link
From source file:com.bdb.weather.display.day.DayPressurePane.java
@Override public List<SeriesControl> configure(Menu menu) { List<SeriesControl> controls = new ArrayList<>(); controls.add(new SeriesControl(HistoricalSeriesInfo.BAROMETER_SERIES, true)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_SOLAR_RADIATION_SERIES, true, false)); XYToolTipGenerator ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getTimeInstance(), Pressure.getDefaultFormatter()); getPlot().getRenderer(0).setBaseToolTipGenerator(ttg); ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getTimeInstance(), SolarRadiation.getDefaultFormatter()); getPlot().getRenderer(1).setBaseToolTipGenerator(ttg); return controls; }
From source file:com.charts.TenYearChart.java
public TenYearChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setBaseToolTipGenerator(/*from ww w . j av a 2 s. co m*/ new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer.setDrawVolume(false); rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(900, 400)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.BLACK); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:ChartUsingJava.CombinedXYPlotDemo1.java
/** * Creates an overlaid chart./*from ww w. j a v a2 s. c om*/ * * @return The chart. */ private static JFreeChart createCombinedChart() { // create plot ... IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); DateAxis domainAxis = new DateAxis("Year"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.02); ValueAxis rangeAxis = new NumberAxis("$billion"); XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... IntervalXYDataset data2 = createDataset2(); XYBarRenderer renderer2 = new XYBarRenderer() { public Paint getItemPaint(int series, int item) { XYDataset dataset = getPlot().getDataset(); if (dataset.getYValue(series, item) >= 0.0) { return Color.red; } else { return Color.green; } } }; renderer2.setSeriesPaint(0, Color.red); renderer2.setDrawBarOutline(false); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); return chart; }
From source file:org.yccheok.jstock.gui.charting.DynamicChart.java
/** Creates new form DynamicChart */ public DynamicChart() { this.price = new TimeSeries("Price"); // Sets the maximumItemAge attribute, which specifies the maximum age of data items in the series // (in terms of the RegularTimePeriod type used by this series). Whenever a new data value is // added, any data items that are older than the limit specified by maximumItemAge are automatically // discarded/*www . j ava2 s .co m*/ // Maximum 2 hours. this.price.setMaximumItemAge(2 * 60 * 60); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.price); JFreeChart freeChart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, true, false); freeChart.setAntiAlias(true); while (freeChart.getSubtitleCount() > 0) { freeChart.removeSubtitle(freeChart.getSubtitle(0)); } // Due to limited spacing, we remove all information regarding x and y axis // as well. XYPlot plot = freeChart.getXYPlot(); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#"))); org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart); // Disable zoom. chartPanel = new ChartPanel(freeChart, true, true, true, false, true); chartPanel.setMouseZoomable(false); }
From source file:net.sourceforge.processdash.ui.web.reports.XYChart.java
/** Create a scatter plot. */ @Override//from w w w. ja va2s .c om public JFreeChart createChart() { JFreeChart chart; String xLabel = null, yLabel = null; if (!chromeless) { xLabel = Translator.translate(data.getColName(1)); yLabel = getSetting("yLabel"); if (yLabel == null && data.numCols() == 2) yLabel = data.getColName(2); if (yLabel == null) yLabel = getSetting("units"); if (yLabel == null) yLabel = "Value"; yLabel = Translator.translate(yLabel); } Object autoZero = parameters.get("autoZero"); boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0 && data.getData(1, 1) instanceof DateData; if (firstColumnContainsDate || parameters.get("xDate") != null) { chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true, false); if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly()) chart.getXYPlot().getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance())); } else { XYDataset src = data.xyDataSource(); chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true, false); if (src instanceof XYToolTipGenerator) { chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src); } String trendLine = getParameter("trend"); if ("none".equalsIgnoreCase(trendLine)) ; else if ("average".equalsIgnoreCase(trendLine)) addTrendLine(chart, XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y"))); else addTrendLine(chart, XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y"))); } if (autoZero != null) { if (!"x".equals(autoZero)) ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true); if (!"y".equals(autoZero)) ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true); } if (data.numCols() == 2) chart.removeLegend(); return chart; }
From source file:com.bdb.weather.display.day.DayWindPane.java
@Override public List<SeriesControl> configure(Menu menu) { List<SeriesControl> controls = new ArrayList<>(); controls.add(new SeriesControl(HistoricalSeriesInfo.AVG_WIND_SPEED_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.AVG_WIND_DIRECTION_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_WIND_SPEED_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_WIND_DIRECTION_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.WIND_GUST_SPEED_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.WIND_GUST_DIRECTION_SERIES, false)); WindItemRenderer renderer = new WindItemRenderer(); getPlot().setRenderer(renderer);/*from www .j ava2 s .co m*/ WeatherSenseConstants.configureGustRenderer(renderer, GUST_SERIES_INDEX); StandardXYToolTipGenerator ttgen = new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getTimeInstance(DateFormat.SHORT), Speed.getDefaultFormatter()); getPlot().getRenderer().setBaseToolTipGenerator(ttgen); return controls; }
From source file:com.bdb.weather.display.day.DayTemperaturePane.java
@Override public List<SeriesControl> configure(Menu menu) { menu.getItems().add(minMaxLabelsItem); minMaxLabelsItem.setOnAction(this); List<SeriesControl> controls = new ArrayList<>(); controls.add(new SeriesControl(HistoricalSeriesInfo.INDOOR_TEMPERATURE_SERIES, true)); controls.add(new SeriesControl(HistoricalSeriesInfo.LOW_OUTDOOR_TEMPERATURE_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_OUTDOOR_TEMPERATURE_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.AVG_OUTDOOR_TEMPERATURE_SERIES, true)); controls.add(new SeriesControl(HistoricalSeriesInfo.DEW_POINT_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HEAT_INDEX_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.WIND_CHILL_SERIES, false)); SensorManager.getInstance().getExtraSensors(SensorType.THERMOMETER).stream().forEach((sensor) -> { controls.add(new SeriesControl(sensor.getName(), false)); });//w w w.ja va 2 s. c o m XYToolTipGenerator ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getTimeInstance(), Temperature.getDefaultFormatter()); getPlot().getRenderer().setBaseToolTipGenerator(ttg); return controls; }
From source file:org.jfree.chart.demo.TimeSeriesDemo8.java
/** * Creates a chart.// w w w . j a v a 2s . com * * @param dataset the dataset. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 8", "Date", "Value", dataset, true, true, false); final XYItemRenderer renderer = chart.getXYPlot().getRenderer(); final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(g); return chart; }
From source file:org.jfree.chart.demo.CombinedXYPlotDemo2.java
/** * Creates a combined XYPlot chart.//w w w . j a v a2s. com * * @return the combined chart. */ private JFreeChart createCombinedChart() { // create subplot 1... final IntervalXYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new XYBarRenderer(0.20); renderer1.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0"))); final XYPlot subplot1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0"))); final XYPlot subplot2 = new XYPlot(data2, new DateAxis("Date"), null, renderer2); // create a parent plot... final CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Value")); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); // return a new chart containing the overlaid plot... return new JFreeChart("Combined (Range) XY Plot", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.jfree.chart.demo.OverlaidXYPlotDemo.java
/** * Creates an overlaid chart./*from w w w. j a v a 2s .c om*/ * * @return The chart. */ private JFreeChart createOverlaidChart() { // create plot ... final IntervalXYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new XYBarRenderer(0.20); renderer1.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); final DateAxis domainAxis = new DateAxis("Date"); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); final ValueAxis rangeAxis = new NumberAxis("Value"); final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1); final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond(); final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); plot.addAnnotation(annotation); // add a second dataset and renderer... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); plot.setDataset(1, data2); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // return a new chart containing the overlaid plot... return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }