我正在使用 JFreeChart 制作折线图。我想在我的折线图上设置工具提示,但我无法在 Servlet 上这样做。所以请帮我在Servlet上设置工具提示?
XYSeriesCollection dataset = new XYSeriesCollection();
for (int i = 0; i < 2; i++) {
XYSeries series = new XYSeries("Name"+i);
for (int j = 0; j < 10; j++) {
series.add(i+j,j+i*j);
}
dataset.addSeries(series);
}
JFreeChart chart= ChartFactory.createXYLineChart("Line Chart Demo 2", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true,false);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(true);
renderer.setShapesFilled(true);
Vector<String> ToolTips1 = new Vector<String>();
for (int j = 0; j < 10; j++)
{
ToolTips1.add("First: "+j);
}
Vector<String> ToolTips2 = new Vector<String>();
for (int j = 0; j < 10; j++)
{
ToolTips2.add("Second: "+j);
}
CustomXYToolTipGenerator generator1 = new CustomXYToolTipGenerator();
generator1.addToolTipSeries(ToolTips1);
CustomXYToolTipGenerator generator2 = new CustomXYToolTipGenerator();
generator2.addToolTipSeries(ToolTips2);
renderer.setSeriesToolTipGenerator(0, generator1);
renderer.setSeriesToolTipGenerator(1, generator2);
renderer.setBaseShape(new Ellipse2D.Double(-3.0, -3.0, 8.0, 8.0));
plot.setRenderer(renderer);
response.setContentType("image/png");
RenderedImage chartImage=chart.createBufferedImage(500,500);
ImageIO.write(chartImage,"png",out);