我使用Vaadin 7.我想保存图表配置并稍后恢复。我在com.vaadin.addon.charts.model.Configuration
中发现一个有趣的事情是你可以将配置序列化为JSON对象。
代码:
chart.getConfiguration().toString();
结果:
{
"type": "column"
},
"title": {
"text": "Chart"
},
"xAxis": {
"categories": [
"f",
"e"
],
"axisIndex": 0
},
"yAxis": {
"min": 0,
"title": {
"text": "Quantity"
},
"axisIndex": 0
},
"tooltip": {
"_fn_formatter": "this.series.name +\u0027: \u0027+ this.y +\u0027 (\u0027+ Math.round(this.percentage) +\u0027%)\u0027"
},
"plotOptions": {
"column": {
"stacking": "normal"
}
},
"series": [
{
"data": [
1,
2
],
"name": "d",
"visible": true
}
],
"exporting": {
"enabled": false
}
}
我现在想要的是从该JSON对象构建配置。有办法吗?
答案 0 :(得分:1)
发现它,实际上非常简单:
Chart chart = new Chart();
//json is the string containing your JSON object
chart.setJsonConfig(json);
//you'll have to draw the chart to update it if needed
//chart.drawChart();