使用JFreeChart制作图表,但是鼠标移动屏幕就闪一下,public void update(Graphics g){paint(g)}不能消除求高手指教
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.*;
import org.jfree.data.time.ohlc.OHLCSeries;
import org.jfree.data.time.ohlc.OHLCSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.*;
public class TimeSeriesDemo1 extends ApplicationFrame implements ChartMouseListener {
public JFreeChart chart;
ChartPanel chartPanel;
private boolean crossedAxis = false;
private double xValue = 0.0;
private double yValue = 0.0;
private int mouseX = 0;
private int mouseY = 0;
private Point2D point;
private Rectangle2D rectangle2D;
private SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
public static XYPlot xyplot;
public Frame frame;
public TimeSeriesDemo1(String s)
{
super(s);
XYDataset xydataset = createDataset();
JFreeChart jfreechart = createChart(xydataset);
chartPanel = new ChartPanel(jfreechart, false);
chartPanel.addChartMouseListener(this);
chartPanel.setPreferredSize(new Dimension(500, 270));
chartPanel.setMouseZoomable(true, false);
chartPanel.setVerticalAxisTrace(true);
chartPanel.setHorizontalAxisTrace(true);
setContentPane(chartPanel);
}
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, true, true, true);
jfreechart.setBackgroundPaint(Color.white);
xyplot = (XYPlot)jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
xyplot.setDomainCrosshairVisible(true);
xyplot.setRangeCrosshairVisible(true);
org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
if(xyitemrenderer instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setBaseShapesFilled(true);
}
DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
return jfreechart;
}
private static XYDataset createDataset()
{
TimeSeries timeseries = new TimeSeries("L&G European Index Trust", org.jfree.data.time.Month.class);
timeseries.add(new Month(2, 2001), 181.80000000000001D);
timeseries.add(new Month(3, 2001), 167.30000000000001D);
timeseries.add(new Month(4, 2001), 153.80000000000001D);
timeseries.add(new Month(5, 2001), 167.59999999999999D);
timeseries.add(new Month(6, 2001), 158.80000000000001D);