如何在jsp中使用JFreeChart显示折线图?
大家好:
我正在使用下面的内容来显示折线图。 当我运行下面的代码时,我得到了窗口,但它是空白的并且不显示图表。 请帮助我,并告诉我如何使用下面的代码在 html 页面中显示折线图。
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.*;
public class xyLine {
public static void main(String arg[]) {
XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 25.0);
series.add(55.0, 50.0);
series.add(70.0, 65.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart(
"XYLine Chart using JFreeChart", "Age", "Weight",
xyDataset, PlotOrientation.VERTICAL, true, true, false);
ChartFrame frame1 = new ChartFrame("XYLine Chart", chart);
frame1.setVisible(true);
frame1.setSize(300, 300);
}
}
HI All:
I am using the below to diplay the line graph. when i run the below code, i am getting the window but it is blank and not displaying the graph. Please help me and also tell me how to diplay the line graph in html page using below code.
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.*;
public class xyLine {
public static void main(String arg[]) {
XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 25.0);
series.add(55.0, 50.0);
series.add(70.0, 65.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart(
"XYLine Chart using JFreeChart", "Age", "Weight",
xyDataset, PlotOrientation.VERTICAL, true, true, false);
ChartFrame frame1 = new ChartFrame("XYLine Chart", chart);
frame1.setVisible(true);
frame1.setSize(300, 300);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我前段时间也这样做过,但我也有代码,所以这是线索..
正如 Thorbjørn Ravn Andersen 所说,您必须有一个 servlet 来生成图像而不是网页。 这意味着您的 servlet 的 processRequest 方法看起来像这样:
然后您可以使用这个 servlet 作为其他页面中的图像源,例如像这样......
然后您就完成了:)
I did this some time ago as well, but I also have the code, so here's the clue..
As Thorbjørn Ravn Andersen said you have to have a servlet generating images instead of web pages. That means that your servlet's processRequest method looks something like this:
Then you can use this servlet as a source of image in other pages for example like this..
And you're done :)
您正在使用摆动方法,该方法在网络设置中不起作用。 您必须生成一个图像,并将其展平为例如 JPEG 字节流,并使用正确的 MIME 类型将其作为 servlet 的响应返回。
我很多个月前就这样做了,但现在没有代码了。
You are using a swing approach which does not work in a web setting. You must generate an Image, and flatten it to e.g. a JPEG byte stream, and return THAT as a response from your servlet with a correct MIME type.
I did this many moons ago but do not have the code anymore.