package com.webonlineapp;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hyjavaapex.chart.Apexchart;

/*
 * A simple proof of concept example application to show how to integrate
 * ApexCharts and the HyJavaApex library in a JSP application.
 * 
 * NOTE: The evaluation library only supports a limited set of ApexCharts chart types and chart options.
 *       The full version of the HyJavaCharts library supports all ApexCharts chart types and chart options.
 *       
 *       We are not experts using JSP's so there will no doubt be better ways to accomplish the same thing.
 * 
 */
@WebServlet("/")
public final class DemoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;


    /**
     * 
     */
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
            throws ServletException, IOException {

        handleRequest(req, resp);
    }

    /**
     * 
     */
    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
            throws ServletException, IOException {

        handleRequest(req, resp);
    }

    /**
     * 
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    private void handleRequest(final HttpServletRequest req, final HttpServletResponse resp)
            throws ServletException, IOException {

		Apexchart apexchart = new ApexChartsBasicColumn().configure();

        req.setAttribute("chartOptions", apexchart.chartOptionsToJs());
        req.getRequestDispatcher("/apexchartsdemo.jsp").forward(req, resp);
    }

}
