我想jfreechart在jsp页面中显示一个图表.我写的代码如下 -
...
<%
ChartCreator chart = new ChartCreator();
chart.createCategoryChart();
%>
<img src = "chart.jpg"/>
Run Code Online (Sandbox Code Playgroud)
其中createCategoryChart()方法创建所需的JPG.它存储在eclipse文件夹中(我没有在我的文件名中放置任何路径).
我无法在jsp页面中查看图表,但是创建了该文件.
我究竟做错了什么?
我建议使用Servlet来创建Chart.
JSP主要用于表示(View).
创建一个servlet,创建图表并将其作为响应发回.
import javax.imageio.ImageIO;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out = response.getOutputStream(); /* Get the output stream from the response object */
response.setContentType("image/png"); /* Set the HTTP Response Type */
ChartCreator chart = new ChartCreator(); // Create chart
chart.createCategoryChart();
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);/* Write the data to the output stream */
}
Run Code Online (Sandbox Code Playgroud)
从JSP调用Servlet.
<img src="/drawChartServlet?type=myDesiredChart&width=..and other processed parameters" ..>
| 归档时间: |
|
| 查看次数: |
6989 次 |
| 最近记录: |