| <!DOCTYPE html> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <script src="lib/simpleRequire.js"></script> |
| <script src="lib/config.js"></script> |
| </head> |
| <body> |
| <style> |
| html, body, #main { |
| margin: 0; |
| width: 100%; |
| height: 100vh; |
| } |
| </style> |
| |
| <div id="main"></div> |
| |
| <script> |
| require(['echarts'], function (echarts) { |
| var chart = echarts.init(document.querySelector("#main"), 'dark'); |
| window.onresize = chart.resize; |
| |
| const sankeyData = [ |
| {source: 'EasyGrid Energy', target: 'Chip Industry', value: 860}, |
| {source: 'EasyGrid Energy', target: 'Industrial Internet', value: 1600}, |
| {source: 'EG Green Energy', target: 'Chip Industry', value: 2600}, |
| {source: 'EG Green Energy', target: 'IOT', value: 500}, |
| |
| {source: 'Industrial Internet', target: 'IOT', value: 800}, |
| {source: 'Industrial Internet', target: 'Intelligent Manufacturing', value: 600}, |
| |
| {source: 'Chip Industry', target: 'Chip Manufacturing', value: 1600}, |
| {source: 'Chip Industry', target: 'Chip Package', value: 1200}, |
| {source: 'Chip Industry', target: 'Chip Design', value: 600}, |
| |
| {source: 'Chip Manufacturing', target: '5mm', value: 600}, |
| {source: 'Chip Manufacturing', target: '10mm', value: 500}, |
| {source: 'Chip Manufacturing', target: '15mm', value: 500} |
| ]; |
| |
| var option = { |
| title: {text: 'The values of Label and Tooltip are the same',padding: 20}, |
| series: [{ |
| type: 'sankey', |
| layout: 'none', |
| lineStyle: {color: 'gradient', curveness: 0.5}, |
| emphasis: {focus: 'adjacency'}, |
| data: getNames(), |
| links: sankeyData, |
| label: { |
| formatter: (params) => { |
| return params.name + ': ' + params.value + ' kW·h'; |
| }, |
| fontWeight: 'bold' |
| }, |
| edgeLabel: { |
| show: true, |
| formatter: (params) => { |
| return params.name + ': ' + params.value; |
| }, |
| // formatter: 'value: {c}' |
| }, |
| emphasis: { |
| edgeLabel: { |
| // formatter: 'emphasis----{c}' |
| } |
| } |
| }], |
| tooltip: {trigger: 'item', triggerOn: 'mousemove'} |
| }; |
| |
| chart.setOption(option); |
| |
| function getNames() { |
| return sankeyData.reduce((names, item) => { |
| if (-1 == names.indexOf(item.source)) { |
| names.push(item.source); |
| } |
| if (-1 == names.indexOf(item.target)) { |
| names.push(item.target); |
| } |
| return names; |
| }, []).map(item => {return {name:item}}); |
| } |
| }); |
| </script> |
| </body> |
| </html> |
| |