controller
@Controller
@RequestMapping("/char")
public class CharController {
@RequestMapping("/show")
public ModelAndView showchar(){
System.out.println("into");
Prem p=new Prem();
p.setName("Tokyo");
p.setData(new float[]{1,2,3,23,23,11,2,5,6,4,5,9});
Prem p1=new Prem();
p1.setName("New York");
p1.setData(new float[]{5,2,13,2,3,11,2,15,6,14,15,19});
//
Title title=new Title();
title.setText("折线图");
title.setX(-20);
//
Subtitle subtitle=new Subtitle();
subtitle.setText("月份-值");
subtitle.setX(-20);
//
Xaxis xaxis=new Xaxis();
xaxis.setCategories(new String[]{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"});
//
YaxisTitle yaxisTitle =new YaxisTitle();
yaxisTitle.setText("temperatrue°C");
PlotLines plotLines=new PlotLines();
plotLines.setValue(0);
plotLines.setColor("#808080");
plotLines.setWidth(1);
Yaxis yaxis=new Yaxis();
yaxis.setPlotLines(new PlotLines[]{plotLines});
yaxis.setTitle(yaxisTitle);
//
Tooltip tooltip=new Tooltip();
tooltip.setValueSuffix("°C");
//
Legend legend=new Legend();
legend.setAlign("right");
legend.setLayout("vertical");
legend.setBorderWidth(0);
legend.setVerticalAlign("middle");
//
Map<String,Object> map=new HashMap<>();
map.put("cvs", "cvs");
//
Highcharts highcharts=new Highcharts();
highcharts.setTitle(title);
highcharts.setSubtitle(subtitle);
highcharts.setXaxis(xaxis);
highcharts.setYaxis(yaxis);
highcharts.setTooltip(tooltip);
highcharts.setLegend(legend);
highcharts.setSeries(new Prem[]{p,p1});
highcharts.setChart(map);
String lin=JSONObject.toJSONString(highcharts).replace("xaxis", "xAxis").replace("yaxis", "yAxis");
String pie=JSONObject.toJSONString(pieChar());
String area=JSONObject.toJSONString(areashow());
String column=JSONObject.toJSONString(columnshow());
String c3dcolumn=JSONObject.toJSONString(c3dcolumn());
//System.out.println(str);
ModelAndView mav=new ModelAndView("index");
mav.addObject("lin", lin);
mav.addObject("pie", pie);
mav.addObject("area", area);
mav.addObject("column", column);
mav.addObject("c3dcolumn", c3dcolumn);
return mav;
}
@RequestMapping(value="/column")
public ModelAndView show3dcolumn(){
ModelAndView mav=new ModelAndView("s3dcolumn");
String c3dcolumn=JSONObject.toJSONString(c3dcolumn());
mav.addObject("c3dcolumn", c3dcolumn);
return mav;
}
public Map<String,Object> loadchar(){
Map<String,Object> chart=new HashMap<>();
chart.put("zoomType", "x");
//
Map<String,Object> title =new HashMap<>();
title.put("text", "USD to EUR exchange rate over time");
//
Map<String,Object> subtitle =new HashMap<>();
subtitle.put("text", "测试");
//
Map<String,Object> xAxis =new HashMap<>();
xAxis.put("type", "datetime");
//
Map<String,Object> yAxis =new HashMap<>();
Map<String,Object> yAxis_title =new HashMap<>();
yAxis_title.put("text", "Exchange rate");
yAxis.put("title", yAxis_title);
//
Map<String,Object> legend=new HashMap<>();
legend.put("enabled", false);
//
Map<String,Object> plotOptions=new HashMap<>();
Map<String,Object> area =new HashMap<>();
Map<String,Object> fillColor=new HashMap<>();
Map<String,Object> linearGradient=new HashMap<>();
linearGradient.put("x1", 0);
linearGradient.put("y1", 0);
linearGradient.put("x2", 0);
linearGradient.put("y2", 0);
return null;
}
public Map<String,Object> pieChar(){
Map<String,Object> chart =new HashMap<>();
chart.put("plotBackgroundColor", null);
chart.put("plotBorderWidth", null);
chart.put("plotShadow", false);
chart.put("type", "pie");
//
Map<String,Object> title =new HashMap<>();
title.put("text", "饼状图");
//
Map<String,Object> tooltip =new HashMap<>();
tooltip.put("pointFormat", "浏览器占比");
//
Map<String,Object> dataLabels=new HashMap<>();
Map<String,Object> pie=new HashMap<>();
Map<String,Object> plotOptions=new HashMap<>();
dataLabels.put("enabled", false);
pie.put("allowPointSelect", true);
pie.put("cursor", "pointer");
pie.put("dataLabels", dataLabels);
pie.put("showInLegend", true);
//
Map<String,Object> data=new HashMap<>();
data.put("name", "Explorer");
data.put("y", 56.33);
Map<String,Object> data1=new HashMap<>();
data1.put("name", "Chrome");
data1.put("y", 24.03);
data1.put("sliced", true);
data1.put("selected", true);
Map<String,Object> data2=new HashMap<>();
data2.put("name", "Firefox");
data2.put("y", 10.38);
Object[] datas =new Object[]{data,data1,data2};
Map<String,Object> series=new HashMap<>();
series.put("name", "Brands");
series.put("colorByPoint", true);
series.put("data", datas);
Map<String,Object> all=new HashMap<>();
all.put("chart", chart);
all.put("title", title);
all.put("tooltip", tooltip);
all.put("plotOptions", plotOptions);
all.put("series", new Object[]{series});
return all;
}
public Map<String,Object> areashow(){
Map<String,Object> chart =new HashMap<>();
chart.put("type", "area");
//
Map<String,Object> title =new HashMap<>();
title.put("text", "面积图");
//
Map<String,Object> subtitle =new HashMap<>();
subtitle.put("text", "对比");
//
Map<String,Object> xAxis_title =new HashMap<>();
xAxis_title.put("enabled", false);
Map<String,Object> xAxis =new HashMap<>();
xAxis.put("categories", new String[]{"1750", "1800", "1850", "1900", "1950", "1999", "2050"});
xAxis.put("tickmarkPlacement","on");
xAxis.put("title",xAxis_title);
//
Map<String,Object> yAxis =new HashMap<>();
Map<String,Object> yAxis_title =new HashMap<>();
yAxis_title.put("text", "Billions");
Map<String,Object> yAxis_labels =new HashMap<>();
yAxis_labels.put("labels", "CCCC");
//
Map<String,Object> tooltip =new HashMap<>();
tooltip.put("shared", true);
tooltip.put("valueSuffix", "millions");
//
Map<String,Object> plotOptions =new HashMap<>();
Map<String,Object> area =new HashMap<>();
Map<String,Object> marker =new HashMap<>();
marker.put("lineWidth", 1);
marker.put("lineColor", "#666666");
area.put("stacking", "normal");
area.put("lineColor", "#666666");
area.put("lineWidth", 1);
area.put("marker", marker);
plotOptions.put("area", area);
//
Map<String,Object> series =new HashMap<>();
series.put("name", "中国");
series.put("data", new int[]{502, 635, 809, 947, 1402, 3634, 5268});
Map<String,Object> series1 =new HashMap<>();
series1.put("name", "美国");
series1.put("data", new int[]{106, 107, 111, 133, 221, 767, 1766});
Map<String,Object> series2 =new HashMap<>();
series2.put("name", "俄罗斯");
series2.put("data", new int[]{163, 203, 276, 408, 547, 729, 628});
Map<String,Object> series3 =new HashMap<>();
series3.put("name", "欧盟");
series3.put("data", new int[]{18, 31, 54, 156, 339, 818, 1201});
Map<String,Object> series4 =new HashMap<>();
series4.put("name", "北约");
series4.put("data", new int[]{2, 2, 2, 6, 13, 30, 46});
//
Map<String,Object> areachar =new HashMap<>();
areachar.put("chart", chart);
areachar.put("title", title);
areachar.put("subtitle", subtitle);
areachar.put("xAxis", xAxis);
areachar.put("yAxis", yAxis);
areachar.put("tooltip", tooltip);
areachar.put("plotOptions", plotOptions);
areachar.put("series", new Object[]{series,series1,series2,series3,series4});
return areachar;
}
public Map<String,Object> columnshow(){
Map<String,Object> chart =new HashMap<>();
chart.put("type", "column");
//
Map<String,Object> title =new HashMap<>();
title.put("text","柱状图");
//
Map<String,Object> subtitle =new HashMap<>();
subtitle.put("text", "对比");
//
Map<String,Object> xAxis =new HashMap<>();
xAxis.put("categories", new String[]{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"});
//
Map<String,Object> yAxis =new HashMap<>();
Map<String,Object> yAxis_title =new HashMap<>();
yAxis_title.put("text", "单位00");
yAxis.put("min", 0);
yAxis.put("title", title);
//
Map<String,Object> tooltip =new HashMap<>();
tooltip.put("headerFormat", "<span style='font-size:10px'>{point.key}</span><table>");
tooltip.put("pointFormat", "<tr><td style='color:{series.color};padding:0'>{series.name}: </td><td style='padding:0'><b>{point.y:.1f} mm</b></td></tr>");
tooltip.put("footerFormat", "</table>");
tooltip.put("shared", true);
tooltip.put("useHTML", true);
//
Map<String,Object> plotOptions =new HashMap<>();
Map<String,Object> column =new HashMap<>();
column.put("pointPadding", 0.2);
column.put("borderWidth", 0);
plotOptions.put("column", column);
//
Map<String,Object> series =new HashMap<>();
series.put("name", "北京");
series.put("data", new double[]{49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4});
Map<String,Object> series1 =new HashMap<>();
series1.put("name", "纽约");
series1.put("data", new double[]{83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3});
Map<String,Object> series2 =new HashMap<>();
series2.put("name", "伦敦");
series2.put("data", new double[]{48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2});
Map<String,Object> series3 =new HashMap<>();
series3.put("name", "柏林");
series3.put("data", new double[]{42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1});
//
Map<String,Object> columnchar =new HashMap<>();
columnchar.put("chart", chart);
columnchar.put("title", title);
columnchar.put("subtitle", subtitle);
columnchar.put("xAxis", xAxis);
columnchar.put("yAxis", yAxis);
columnchar.put("tooltip", tooltip);
columnchar.put("plotOptions", plotOptions);
columnchar.put("series", new Object[]{series,series1,series2,series3});
return columnchar;
}
public Map<String,Object> c3dcolumn(){
Map<String,Object> chart =new HashMap<>();
Map<String,Object> options3d =new HashMap<>();
options3d.put("enabled", true);
options3d.put("alpha", 15);
options3d.put("beta", 15);
options3d.put("depth", 50);
options3d.put("viewDistance", 25);
chart.put("renderTo", "s3dcolumn");
chart.put("type", "column");
chart.put("options3d", options3d);
//
Map<String,Object> title =new HashMap<>();
title.put("text", "3D柱状图");
//
Map<String,Object> subtitle =new HashMap<>();
subtitle.put("text", "小标题");
//
Map<String,Object> column =new HashMap<>();
Map<String,Object> plotOptions =new HashMap<>();
column.put("depth", 25);
column.put("plotOptions", column);
//
Map<String,Object> series =new HashMap<>();
series.put("data", new double[]{29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4});
series.put("name", "NO1");
Map<String,Object> series1 =new HashMap<>();
series1.put("data", new double[]{21.9, 51.5, 16.4, 29.2, 44.0, 176.0, 15.6, 118.5, 116.4, 294.1, 195.6, 154.4});
series1.put("name", "NO2");
Map<String,Object> s3dcolumn =new HashMap<>();
s3dcolumn.put("chart", chart);
s3dcolumn.put("title", title);
s3dcolumn.put("subtitle", subtitle);
s3dcolumn.put("plotOptions", plotOptions);
s3dcolumn.put("series", new Object[]{series,series1});
return s3dcolumn;
}
}
jsp
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
#container, #sliders {
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
#container {
height: 400px;
}
</style>
<script type="text/javascript">
var lin=${lin};
var pie=${pie};
var area=${area};
var column=${column};
var c3dcolumn=${c3dcolumn};
$(function () {
$('#lin').highcharts(lin);
$('#pie').highcharts(pie);
$('#area').highcharts(area);
$('#column').highcharts(column);
});
<!---->
var chart = new Highcharts.Chart(c3dcolumn);
function showValues() {
$('#alpha-value').html(chart.options.chart.options3d.alpha);
$('#beta-value').html(chart.options.chart.options3d.beta);
$('#depth-value').html(chart.options.chart.options3d.depth);
}
// Activate the sliders
$('#sliders input').on('input change', function () {
chart.options.chart.options3d[this.id] = this.value;
showValues();
chart.redraw(false);
});
showValues();
</script>
</head>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<table>
<tr><td><div id="lin"></div></td><td><div id="column"></div></td> </tr>
<tr><td><div id="pie"></div></td><td></td></tr>
<tr><td><div id="area"></div></td><td></td> </tr>
</table>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
#container, #sliders {
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
#container {
height: 400px;
}
</style>
<script type="text/javascript">
var c3dcolumn =${c3dcolumn};
$(function () {
// Set up the chart
var chart = new Highcharts.Chart(c3dcolumn);
function showValues() {
$('#alpha-value').html(chart.options.chart.options3d.alpha);
$('#beta-value').html(chart.options.chart.options3d.beta);
$('#depth-value').html(chart.options.chart.options3d.depth);
}
// Activate the sliders
$('#sliders input').on('input change', function () {
chart.options.chart.options3d[this.id] = this.value;
showValues();
chart.redraw(false);
});
showValues();
});
</script>
</head>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="s3dcolumn"></div>
<div id="sliders">
<table>
<tr>
<td>Alpha Angle</td>
<td><input id="alpha" type="range" min="0" max="45" value="15"/> <span id="alpha-value" class="value"></span></td>
</tr>
<tr>
<td>Beta Angle</td>
<td><input id="beta" type="range" min="-45" max="45" value="15"/> <span id="beta-value" class="value"></span></td>
</tr>
<tr>
<td>Depth</td>
<td><input id="depth" type="range" min="20" max="100" value="50"/> <span id="depth-value" class="value"></span></td>
</tr>
</table>
</div>
</body>
</html>