我曾經用於Spring MVC。這是我的Java服務如何更改HighCharts中的「餅圖」中的代碼
@Override
public ArrayList<SampleVO1> getAvgPetalBySpecies3() {
ArrayList<SampleVO1> irisList = new ArrayList<SampleVO1>();
try {
REXP result = rEngine.eval("(ming <- tapply(iris$Petal.Length, iris$Species, mean))");
REXP result1 = rEngine.eval("names(ming)");
SampleVO1 sample1 = new SampleVO1();
sample1.setName(result1.asStringArray());
sample1.setY(result.asDoubleArray());
irisList.add(sample1);
} catch (Exception e) {
logger.error(e.getMessage());
throw new RuntimeException(e);
}
return irisList;
}
哦!這是我的VO
private String[] name;
private double[] y;
,這是我的控制器
@RequestMapping("/analytics/iris3")
public String getAvgPetalbySpecies3(Model model) {
ArrayList<SampleVO1> irisList = analyticsService.getAvgPetalBySpecies3();
Gson gson = new Gson();
String irisData = gson.toJson(irisList);
model.addAttribute("irisData2", irisData);
return "analytics/visual";
}
最後,這是我的JSP
<script type="text/javascript">
$(function() {
Highcharts.chart('pie', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true
},
showInLegend: true
}
},
series:
<%= request.getAttribute("irisData2") %>,
});
});
</script>
笑我看到白色的空間... 我檢查了我的源代碼!
series:
[{"name":["setosa","versicolor","virginica"],"y":[1.462,4.26,5.552]}],
我以爲我收到不錯的虹膜數據!但我highCharts不喜歡那個... 我如何解決我的代碼...?
您的系列數據格式不正確。請查看[系列。數據](http://api.highcharts.com/highcharts/series%3Cpie%3E.data),瞭解如何正確格式化數據。 –
ewolden
是啊...我知道我讀了高畫......但如何更改我的service.java ... – Ming9Mang9