| <!-- | |
| 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"> | |
| <script src="lib/simpleRequire.js"></script> | |
| <script src="lib/config.js"></script> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| </head> | |
| <body> | |
| <style> | |
| #main0 { | |
| width: 100%; | |
| height: 2000px; | |
| margin: 20px 0; | |
| } | |
| </style> | |
| <h3>Pie series label rotate</h3> | |
| <button onclick="run()">Run</button> | |
| <div id="main0"></div> | |
| <script> | |
| var chart; | |
| var series = []; | |
| function run() { | |
| setInterval(function () { | |
| for (var i = 0; i < series.length; ++i) { | |
| for (var j = 0; j < series[i].data.length; ++j) { | |
| series[i].data[j] = Math.floor(Math.random() * 100) / 10; | |
| } | |
| series[i].startAngle = Math.random() * 360 - 180; | |
| } | |
| chart.setOption({ | |
| series: series | |
| }); | |
| }, 4000); | |
| } | |
| require(['echarts'], function (echarts) { | |
| function setPieChart() { | |
| var positions = [ | |
| 'inner', 'center', 'outside' | |
| ]; | |
| var rotates = [ | |
| undefined, | |
| 'radial', | |
| 'tangential', | |
| 30 | |
| ]; | |
| chart = echarts.init(document.getElementById('main0')); | |
| var rows = positions.length; | |
| var cols = rotates.length; | |
| var title = []; | |
| for (var rot = 0; rot < 2; ++rot) { | |
| for (var i = 0; i < rows; ++i) { | |
| for (var j = 0; j < cols; ++j) { | |
| series.push({ | |
| type: 'pie', | |
| data: [ | |
| 2, | |
| 1.2, | |
| 2.4, | |
| 3.6 | |
| ], | |
| label: { | |
| show: true, | |
| position: positions[i], | |
| rotate: rotates[j], | |
| formatter: 'value: {c}', | |
| borderColor: '#0ff', | |
| borderWidth: 2 | |
| }, | |
| labelLayout: { | |
| hideOverlap: false | |
| }, | |
| center: [ | |
| 100 / cols * (j + 0.5) + '%', | |
| 100 / rows / 2 * (i + 0.5 + rot * 3) + '%' | |
| ], | |
| startAngle: rot ? 90 : 0, | |
| radius: [ | |
| 30, | |
| 100 / rows / 2 * 0.6 + '%' | |
| ] | |
| }); | |
| var rotText = j === 3 ? '30°' : rotates[j]; | |
| title.push({ | |
| text: 'startAngle: ' + (rot ? 0 : 90) + '\n' + positions[i] + ', rotate: ' + rotText, | |
| left: 100 / cols * (j + 0.5) + '%', | |
| top: 100 / rows / 2 * (i + 0.85 + rot * 3) + '%', | |
| textAlign: 'center' | |
| }); | |
| } | |
| } | |
| } | |
| chart.setOption({ | |
| title: title, | |
| tooltip: {}, | |
| series: series, | |
| backgroundColor: '#fff', | |
| animation: 0 | |
| }); | |
| } | |
| setPieChart(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |