ECharts-Java option 的转换json方法

hello_bear 发布于 2015/01/06 17:33
阅读 5K+
收藏 0

@Liuzh_533 你好,想跟你请教个问题:

        Option option = new Option();
        CategoryAxis categoryAxis = new CategoryAxis();
        categoryAxis.data("北京","天津","上海","山东","辽宁","内蒙古","河南","河北","江苏","浙江","西藏","新疆");
        option.xAxis(categoryAxis);
        ValueAxis valueAxis = new ValueAxis();
        valueAxis.axisLabel().formatter("{value} %");
        option.yAxis(valueAxis);
        Bar bar = new Bar();
        bar.name("平台建设情况");
        bar.data(2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3);
        option.series(bar);
        JSONArray json = JSONArray.fromObject(option);
        return json.toString();



你好有个问题问你一下,你例子中的option.view方法为什么没有呢? 我用上面的方法转换的json。

但是结果不正确。

[{"animation":false,"backgroundColor":null,"calculable":false,"color":[],"dataRange":null,"dataZoom":null,"grid":null,"itemStyle":null,"legend":null,"options":[],"polar":[],"renderAsImage":null,"series":[{"barCategoryGap":"","barGap":"","barMinHeight":0,"data":[2,4.9,7,23.2,25.6,76.7,135.6,162.2,32.6,20,6.4,3.3],"itemStyle":null,"markLine":null,"markPoint":null,"name":"平台建设情况","showAllSymbol":false,"stack":"","symbol":null,"symbolRoate":null,"symbolSize":null,"tooltip":null,"type":{},"xAxisIndex":0,"yAxisIndex":0}],"timeline":null,"title":null,"toolbox":null,"tooltip":null,"xAxis":[{"axisLabel":null,"axisLine":null,"axisTick":null,"boundaryGap":null,"data":["北京","天津","上海","山东","辽宁","内蒙古","河南","河北","江苏","浙江","西藏","新疆"],"name":"","nameLocation":null,"nameTextStyle":null,"position":null,"splitArea":null,"splitLine":null,"type":{}}],"yAxis":[{"axisLabel":{"clickable":false,"color":"","formatter":"{value} %","interval":null,"margin":0,"position":null,"rotate":0,"show":false,"textStyle":null},"axisLine":null,"axisTick":null,"boundaryGap":null,"data":[],"max":0,"min":0,"name":"","nameLocation":null,"nameTextStyle":null,"position":null,"power":0,"precision":0,"scale":false,"splitArea":null,"splitLine":null,"splitNumber":0,"type":{}}]}]


加载中
0
hello_bear
hello_bear

自己转换json的方法有点不适用。

根据作者说明,用GsonOption 的 toString方法,问题解决~

0
Liuzh_533
Liuzh_533

应该是JsonObject,不应该使用JsonArray.

另外GsonOption中特殊处理了function的字符串,不过最近发现生成的字符串有多余的空格,下次版本更新会解决这个问题。

view这个方法是测试代码中的一个特殊的Option中的。下次更新也添加到正式代码中。

返回顶部
顶部