Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use json list file in javascript file to draw stacked bar chart
    primarykey
    data
    text
    <p>I have used list in my java class and i am successfully retrieving values from database and showing it in a table, now i wanted to display those list values in stacked bar chart so i have used Json. once i run the java class it will create file.json in F drive, so now how can i use that file and display those list values in jsp.</p> <p>here is my java class.</p> <pre><code>package com.rashmi.action; import java.sql.*; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.io.FileWriter; import java.io.IOException; import com.google.gson.Gson; public class FebruaryAction { List abc = new ArrayList(); public List getAbc() { return abc; } public void setAbc(List abc) { this.abc = abc; } public String execute() throws Exception { Connection con = GetCon.getCon(); Statement statement = con.createStatement(); ResultSet resultset = statement.executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate &gt;= '2013-02-01' AND OrderDate &lt;= '2013-02-28' AND MarketPlace= 'AUK' GROUP BY OrderDate,MarketPlace"); while (resultset.next()) { String marketplace = resultset.getString(1); String orderdate = resultset.getString(2); Double datamount = resultset.getDouble(3); Integer count = resultset.getInt(4); Double result = resultset.getDouble(5); ReportClass a = new ReportClass(); a.setMarketplace(marketplace); a.setOrderdate(orderdate); a.setDataamount(datamount); a.setCount(count); a.setResult(result); abc.add(a); String json = new Gson().toJson(abc); try { FileWriter writer = new FileWriter("F:\\file.json"); writer.write(json); writer.close(); } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>My jsp page</p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;%@page import="java.sql.*,javax.*" %&gt; &lt;%@taglib prefix="s" uri="/struts-tags" %&gt; &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;%@ page import="com.rajesh.action.*" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;January&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Report for January&lt;/h1&gt; &lt;body&gt; &lt;table border="1" &gt; &lt;tr&gt; &lt;th&gt;Market&lt;/th&gt; &lt;th&gt;Jan-01&lt;/th&gt; &lt;th&gt;Jan-02&lt;/th&gt; &lt;th&gt;Jan-03&lt;/th&gt; &lt;th&gt;Jan-04&lt;/th&gt; &lt;th&gt;Jan-05&lt;/th&gt; &lt;th&gt;Jan-06&lt;/th&gt; &lt;th&gt;Jan-07&lt;/th&gt; &lt;th&gt;Jan-08&lt;/th&gt; &lt;th&gt;Jan-09&lt;/th&gt; &lt;th&gt;Jan-10&lt;/th&gt; &lt;th&gt;Jan-11&lt;/th&gt; &lt;th&gt;Jan-12&lt;/th&gt; &lt;th&gt;Jan-13&lt;/th&gt; &lt;th&gt;Jan-14&lt;/th&gt; &lt;th&gt;Jan-15&lt;/th&gt; &lt;th&gt;Jan-16&lt;/th&gt; &lt;th&gt;Jan-17&lt;/th&gt; &lt;th&gt;Jan-18&lt;/th&gt; &lt;th&gt;Jan-19&lt;/th&gt; &lt;th&gt;Jan-20&lt;/th&gt; &lt;th&gt;Jan-21&lt;/th&gt; &lt;th&gt;Jan-22&lt;/th&gt; &lt;th&gt;Jan-23&lt;/th&gt; &lt;th&gt;Jan-24&lt;/th&gt; &lt;th&gt;Jan-25&lt;/th&gt; &lt;th&gt;Jan-26&lt;/th&gt; &lt;th&gt;Jan-27&lt;/th&gt; &lt;th&gt;Jan-28&lt;/th&gt; &lt;th&gt;Jan-29&lt;/th&gt; &lt;th&gt;Jan-30&lt;/th&gt; &lt;th&gt;Jan-31&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td rowspan="3"&gt;AUK&lt;/&gt; &lt;c:forEach items="${abc}" var="item"&gt; &lt;td&gt;${item.count}&lt;/td&gt; &lt;/c:forEach&gt; &lt;/tr&gt; &lt;tr&gt; &lt;c:forEach items="${abc}" var="item"&gt; &lt;td&gt;${item.dataamount}&lt;/td&gt; &lt;/c:forEach&gt; &lt;/tr&gt; &lt;tr&gt; &lt;c:forEach items="${abc}" var="item"&gt; &lt;td&gt;${item.result}&lt;/td&gt; &lt;/c:forEach&gt; &lt;/tr&gt; &lt;/table&gt; &lt;script type="text/javascript" src="plugins/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jquery.jqplot.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jquery.jqplot.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.barRenderer.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.barRenderer.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.categoryAxisRenderer.min.js"&gt; &lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.pointLabels.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.canvasAxisTickRenderer.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.canvasAxisTickRenderer.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.canvasOverlay.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.categoryAxisRenderer.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.pointLabels.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.highlighter.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.cursor.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/jqplot.dateAxisRenderer.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/excanvas.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="plugins/excanvas.min.js"&gt;&lt;/script&gt; &lt;link href="plugins/jquery.jqplot.css" rel="stylesheet" /&gt; &lt;link href="plugins/jquery.jqplot.min.css" rel="stylesheet" /&gt; &lt;body&gt; &lt;span id="info3"&gt;Nothing yet.&lt;/span&gt; &lt;div id="chart3" style="height:900px;width:1300px; "&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ var s1 = []; var s2 = []; var s3 = []; &lt;c:forEach var="temp" items="${abc}"&gt; s1.push('${item.result}'); &lt;/c:forEach&gt; &lt;c:forEach var="temp" items="${abc}"&gt; s2.push('${item.count}'); &lt;/c:forEach&gt; &lt;c:forEach var="temp" items="${abc}"&gt; s3.push('${item.dataamount}'); &lt;/c:forEach&gt; var axisDates = ["Jan 1", "Jan 2", "Jan 3","Jan 4","Jan 5","Jan 6","Jan 7","Jan 8","Jan 9","Jan 10","Jan 11","Jan 12","Jan 13","Jan 14","Jan 15","Jan 16","Jan 17","Jan 18","Jan 19","Jan 20","Jan 21","Jan 22","Jan 23","Jan 24","Jan 25","Jan 26","Jan 27","Jan28","Jan 29","Jan 30","Jan 31"] plot3 = $.jqplot('chart3', [s1, s2, s3], { stackSeries: true, varyBarColor: true, captureRightClick: true, animate : !$.jqplot.use_excanvas, seriesDefaults : { renderer:$.jqplot.BarRenderer, rendererOptions: { barPadding : 20, barMargin : 25, barDirection : 'vertical', barWidth : 30, shadowOffset : 4, highlightMouseOver: true }, pointLabels: {show: true} }, axes: {xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: axisDates }, yaxis: {min:0, max: 2300 } }, legend: { show: true, location: 'e', placement: 'outside' } }); // Bind a listener to the "jqplotDataClick" event. Here, simply change // the text of the info3 element to show what series and ponit were // clicked along with the data for that point. $('#chart3').bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) { $('#info3').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data); } ); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload