--------单个柱状
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Highcharts Example</title> <!-- 1. Add these JavaScript inclusions in the head of your page --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript" src="js/highcharts.js"></script> <!-- 1a) Optional: add a theme file --> <!-- <script type="text/javascript" src="../js/themes/gray.js"></script> --> <!-- 1b) Optional: the exporting module --> <script type="text/javascript" src="js/modules/exporting.js"></script> <!-- 2. Add the JavaScript to initialize the chart on document ready --> <script type="text/javascript"> var datastr = "<c:forEach items='${listDetail}' var='l'>${l.score},</c:forEach>"; datastr = "[" + datastr.substring(0, datastr.length - 1) + "]"; var datas = eval(datastr); var datastrs = "<c:forEach items='${listDetail}' var='l'>'${l.subject}',</c:forEach>"; datastrs = "[" + datastrs.substring(0, datastrs.length - 1) + "]"; var data = eval(datastrs); var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'container', defaultSeriesType: 'column', margin: [ 50, 50, 100, 80] }, title: { text: 'Inverter Station' }, xAxis: { categories: data, labels: { rotation: -45, align: 'right', style: { font: 'normal 13px Verdana, sans-serif' } } }, yAxis: { min: 0, title: { text: 'Population (millions)' } }, legend: { enabled: false }, tooltip: { formatter: function() { return '<b>'+ this.x +'</b><br/>'+ 'Station 2011: '+ Highcharts.numberFormat(this.y, 1) + ' millions'; } }, series: [{ name: 'Population', data: datas, dataLabels: { enabled: true, rotation: -90, color: '#FFFFFF', align: 'right', x: -3, y: 10, formatter: function() { return this.y; }, style: { font: 'normal 13px Verdana, sans-serif' } } }] }); }); </script> </head> <body> <!-- 3. Add the container --> <div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div> </body> </html>
---------多个柱状
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Highcharts Example</title> <!-- 1. Add these JavaScript inclusions in the head of your page --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript" src="js/highcharts.js"></script> <!-- 1a) Optional: add a theme file --> <!-- <script type="text/javascript" src="../js/themes/gray.js"></script> --> <!-- 1b) Optional: the exporting module --> <script type="text/javascript" src="js/modules/exporting.js"></script> <!-- 2. Add the JavaScript to initialize the chart on document ready --> <script type="text/javascript"> var str = "<c:forEach items='${listDetail}' var='list' >{name:'${list.subject}',"+ "data:[<c:forEach items='${listDetail}' var='listScore'>${list.score },</c:forEach>]},</c:forEach>"; str="["+str.substring(0, str.length-1)+"]"; var data = eval(str); var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'container', defaultSeriesType: 'column' }, title: { text: 'Monthly Average Rainfall' }, subtitle: { text: 'Source: WorldClimate.com' }, xAxis: { categories: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] }, yAxis: { min: 0, title: { text: 'Rainfall (mm)' } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0 }, tooltip: { formatter: function() { return ''+ this.x +': '+ this.y +' mm'; } }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series:data }); }); </script> </head> <body> <!-- 3. Add the container --> <div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div> </body> </html>