echarts多折线 重叠图

静态demo代码
option = {
    title: {
        text: '折线图堆叠'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
	    //上面显示的类别
        data: ['权限内外商投资企业变更为内资企业', '权限内外商投资企业变更为外资企业']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['2021-01-25', '2021-01-26']
        //x轴坐标名称
    },
    yAxis: {
        type: 'value'
    },
    series: [
    //series是个数组,数组中每个json对象对应一个类别
  	//有多少个类别就有多少个折线
    {//json对象中的type:line代表折线类型
    //name就是类别名称,需要和legend里保持一致
        "data":[
            //data对应的事是n数组
               [ "2021-01-25","1"]
            ,//json数组中对应多个json数组,里面存的是多个折线的点
            //每个点对应的json数组,存值有一定的讲究,需要是[x轴坐标名称,数值]这个格式
               [ "2021-01-26","2"]
            
        ],
        "name":"权限内外商投资企业变更为内资企业",
        "type":"line"
    },
    {
        "data":[
            
                ["2021-01-26","2"]
            
        ],
        "name":"权限内外商投资企业变更为外资企业",
        "type":"line"
    }
]
};
java代码拼装所需的数据
        JSONArray target = new JSONArray();
        for (int i = 0; i < list.size(); i++) {
            if(list != null && !list.isEmpty()){
                JSONObject tempJson1 = new JSONObject();
                String appointment_item = "";
                List<Map<String, String>> list2 = list.get(i);
                JSONArray data2 = new JSONArray();
                for (int i1 = 0; i1 < list2.size(); i1++) {
                    JSONArray dataarar = new JSONArray();
                    Map map = list2.get(i1);
                    String tname = CommonDao.isnull(map.get("name"));
                    appointment_item = CommonDao.isnull(map.get("appointment_item"));
                    String value = CommonDao.isnull(map.get("num"));  
                    if("".equals(names)){
                        names = "'"+tname+"'";
                      //names为x轴数据,通过indexOf函数去重
                    }else{
                        if(names.indexOf(tname) < 0){
                            names += ",'" + tname + "'";
                           }
                    }
                    if("".equals(topnames)){
	                    //拼接为类别,通过indexOf函数去重
                        topnames = "'"+appointment_item+"'";
                    }else{
                        if(topnames.indexOf(appointment_item) < 0){
                            topnames += ",'" + appointment_item + "'";
                        }
                    }
                    JSONArray jjj = new JSONArray();
                    jjj.add(tname);
                    jjj.add(value);
                    dataarar.add(jjj);
 
                    data2.addAll(dataarar);
                }
       
                tempJson1.put("name",appointment_item);
                tempJson1.put("type","line");
                tempJson1.put("data",data2);
                target.add(tempJson1);
            }
        }
        //无数据时
        JSONObject ttjson = result.getJSONObject(0);
        JSONArray jjson = ttjson.getJSONArray("data");
        if (jjson == null || jjson.isEmpty() || jjson.size() == 0) {
            names = "'暂无'";
            String data = "[{value:0,name:'暂无'}]";
            JSONObject tempJson1 = new JSONObject();
            tempJson1.put("name","");
            tempJson1.put("type","line");
            tempJson1.put("data",data);
            target.add(tempJson1);
        }
最终效果

echarts多折线 重叠图_第1张图片
echarts多折线 重叠图_第2张图片

你可能感兴趣的:(前端,json,jquery,echarts)