数据结构采用树形结构,代码配置器中: // 获取数据 var TABLE_DATA = getData("data1"); // 定义一组不同的颜色方案 const colorSchemes = [ { fromColor: '#0C1622', toColor: '#06647D', labelColor: '#00E3FE' }, { fromColor: '#051B32', toColor: '#05508A', labelColor: '#0092FF' }, { fromColor: '#23203B', toColor: '#43396D', labelColor: '#9065FD' }, { fromColor: '#502630', toColor: '#72353D', labelColor: '#D06168' }, { fromColor: '#2C3E42', toColor: '#4E6170', labelColor: '#7DA7BD' }, { fromColor: '#380C30', toColor: '#430D3E', labelColor: '#A85599' }, { fromColor: '#4A450E', toColor: '#625A12', labelColor: '#ADA55C' }, { fromColor: '#294421', toColor: '#3F6B30', labelColor: '#77B05F' }, { fromColor: '#463428', toColor: '#584133', labelColor: '#D19A71' } ]; // 配置选项 option = { backgroundColor: '#000', grid: { left: 0, right: 0, top: 0, bottom: 0 }, series: [{ type: 'treemap', width: '100%', height: '100%', top: 0, left: 0, right: 0, bottom: 0, roam:false, nodeClick:false, data: TABLE_DATA.map((item, index) => { // 循环使用颜色方案 const colorIndex = index % colorSchemes.length; const colors = colorSchemes[colorIndex]; // 只处理主节点 return { name: item.name, value: item.value, itemStyle: { color: { type: 'radial', x: 0.5, y: 0.5, r: 1, colorStops: [{ offset: 0, color: colors.fromColor }, { offset: 1, color: colors.toColor }], global: false } }, label: { color: colors.labelColor, fontSize: 14, fontWeight: 'bold' } }; }), label: { show: true, formatter: '{b}\n{c}', fontSize: 14 }, breadcrumb: { show: false }, itemStyle: { borderWidth: 0 }, levels: [{ itemStyle: { borderWidth: 0 } }], animationDuration: 1000, animationEasing: 'quinticInOut' }] }; // 使用配置项 myChart.setOption(option);
|