zengqinn123 2020-01-01 19:46 采纳率: 0%
浏览 262

Java 如何配置echart 的 option的多个grid

Java如果调用echart的API配置同一个option里设置多个grid
像这样 grid: [
        {x: '5%', y: '5%', width: '40%', height: '16%'},
        {x: '60%', y: '5%', width: '40%', height: '16%'},
        {x: '5%', y: '35%', width: '40%', height: '16%'},
        {x: '60%', y: '35%', width: '40%', height: '16%'},
       {x: '5%', y: '85%', width: '40%', height: '16%'},
        {x: '60%', y: '85%', width: '40%', height: '16%'}
    ],

    如果设置多个option.grid()方法则会覆盖之前的,如果设置多个x,y的值也是会覆盖之前的,不知道怎么设置,求救
  • 写回答

1条回答 默认 最新

  • Kanhumm 2023-11-28 16:00
    关注
    
    import org.json.JSONArray;
    import org.json.JSONObject;
    
    public class Main {
        public static void main(String[] args) {
            JSONObject option = new JSONObject();
            JSONArray gridArray = new JSONArray();
    
            JSONObject grid1 = new JSONObject();
            grid1.put("x", "5%");
            grid1.put("y", "5%");
            grid1.put("width", "40%");
            grid1.put("height", "16%");
            gridArray.put(grid1);
    
            JSONObject grid2 = new JSONObject();
            grid2.put("x", "60%");
            grid2.put("y", "5%");
            grid2.put("width", "40%");
            grid2.put("height", "16%");
            gridArray.put(grid2);
    
            // 添加更多的grid...
    
            option.put("grid", gridArray);
    
            System.out.println(option.toString());
        }
    }
    
    
    评论

报告相同问题?