Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:31:46+00:00 2026-06-13T11:31:46+00:00

I have created web project in struts2.in that i have plotted a graph using

  • 0

I have created web project in struts2.in that i have plotted a graph using jfreechart which i have implemented in my Action class.

http://www.java2s.com/Code/Java/Chart/JFreeChartTimeSeriesDemo10withperminutedata.htm

which displays the graph in separate applet kind of window i googled and find a way to save this chart as image so that in my jsp file i can include this image.
But at the end when i was deploying i had to convert my project into a WAR file but if i convert project to a WAR i cant access images(graph) which gets changed based on users request.So i thought of save the chart/image in a buffer or some thing so that it gets displayed later deleted as soon new graph is requested or user logs out.

So can you ppl give some idea as to how to accomplish this.
Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:31:46+00:00Added an answer on June 13, 2026 at 11:31 am

    I have written something similar to what you are trying to do. The way I accomplished this was to have a second servlet (very simple) that takes in parameters based on the requested chart and generates the chart as a PNG. Basically, you call the servlet with the required parameters. You take those parameters and build your chart. The important part of returning the chart is happening in ChartUtilities.writeChartAsPNG(out, chart, 640, 480) where the first parameter is the output stream for the response to the calling page. The second parameter is the chart you have built. The last two parameters are used for the size of the image. When you call this servlet it would be inside of

    <img src="URL_to_Servlet" />
    

    with the URL containing the needed parameters to build the chart.

    Below is the code you will need, focusing solely on returning the chart as a dynamically built image from a Servlet.

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.jfree.chart.ChartUtilities;
    import org.jfree.chart.JFreeChart;
    
    public class ChartServlet extends HttpServlet {
    
        /*
         * (non-Javadoc) @see
         * javax.servlet.http.HttpServlet#doGet(
         * javax.servlet.http.HttpServletRequest,
         * javax.servlet.http.HttpServletResponse)
         */
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
            JFreeChart chart = this.generateLineChart();
            ServletOutputStream out = resp.getOutputStream();
            resp.setContentType("image/png");
            ChartUtilities.writeChartAsPNG(out, chart, 640, 480);
            out.close();
        }
    
        /**
         * Generate chart.
         *
         * @return the j free chart
         * @throws IOException Signals that an I/O exception has occurred.
         */
        private JFreeChart generateLineChart() throws IOException {
    
            return chart;
        }
    
        /*
         * (non-Javadoc) @see javax.servlet.GenericServlet#init()
         */
        @Override
        public void init() throws ServletException {
            // TODO Auto-generated method stub
            System.out.println("Starting up charts servlet.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created dynamic web project. In that I have written one Java class
I have created a maven web project using the below site. http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/ I have
I have recently created a web project in Java using eclipse. I have a
I have created a web application with a Silverlight project embedded in it, using
I am using Eclipse (J2EE Galileo) and have created a dynamic web project and
I have a problem with a Web Application project which I have created. Originally
I am using VS 2008. I have created a new Asp.net web site project
I have created a web application using Jersey and Dynamic Web Project of Eclipse.
I have created a Web Setup project using VS 2008. I have created a
I have created a Silverlight project which also contains a Web project. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.