堆疊圖是ECharts中使用的一種常見類型,可以方便地展示數(shù)據(jù)的堆疊情況。在使用ECharts繪制堆疊圖時(shí),需要使用JSON格式的數(shù)據(jù)來進(jìn)行配置。以下是一段使用JSON格式配置ECharts堆疊圖的示例代碼:
{ "title": { "text": "ECharts堆疊圖示例", "subtext": "堆疊圖", "left": "center" }, "tooltip": { "trigger": "axis", "axisPointer": { "type": "cross", "crossStyle": { "color": "#999" } } }, "legend": { "data":["數(shù)據(jù)1","數(shù)據(jù)2","數(shù)據(jù)3","數(shù)據(jù)4"], "top":"20" }, "grid": { "left": "3%", "right": "4%", "bottom": "3%", "containLabel": true }, "xAxis" : [ { "type" : "category", "boundaryGap" : false, "data" : ["周一","周二","周三","周四","周五","周六","周日"] } ], "yAxis" : [ { "type" : "value" } ], "series" : [ { "name":"數(shù)據(jù)1", "type":"line", "stack": "堆疊1", "data":[120, 132, 101, 134, 90, 230, 210] }, { "name":"數(shù)據(jù)2", "type":"line", "stack": "堆疊1", "data":[220, 182, 191, 234, 290, 330, 310] }, { "name":"數(shù)據(jù)3", "type":"line", "stack": "堆疊2", "data":[150, 232, 201, 154, 190, 330, 410] }, { "name":"數(shù)據(jù)4", "type":"line", "stack": "堆疊2", "data":[320, 332, 301, 334, 390, 330, 320] } ] }
在上述代碼中,title表示堆疊圖的標(biāo)題,tooltip設(shè)置了交互提示框的相關(guān)參數(shù),legend設(shè)置了數(shù)據(jù)系列的名稱,grid則是設(shè)置了圖表的坐標(biāo)系。xAxis和yAxis則分別設(shè)置了x軸和y軸的類型和數(shù)據(jù)。最后,series表示各個(gè)數(shù)據(jù)系列的相關(guān)信息,包括名稱、類型、堆疊方式和數(shù)據(jù)。