123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <!DOCTYPE>
- <html>
- <head>
- <meta charset="utf-8">
- <script src="lib/esl.js"></script>
- <script src="lib/config.js"></script>
- <script src="lib/jquery.min.js"></script>
- <script src="lib/facePrint.js"></script>
- <script src="lib/testHelper.js"></script>
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <link rel="stylesheet" href="lib/reset.css">
- </head>
- <body>
- <style>
- h1 {
- line-height: 60px;
- height: 60px;
- background: #146402;
- text-align: center;
- font-weight: bold;
- color: #eee;
- font-size: 14px;
- }
- #main {
- width: 100%;
- height: 600px;
- }
- </style>
- 宽度大于600时显示方块,当前宽度:<span id='wid'></span>
- <div id="main"></div>
- <script>
- var echarts;
- var chart;
- var myChart;
- var groupCategories = [];
- var groupColors = [];
- require([
- 'echarts'
- // 'echarts/component/graphic'
- ], function (ec) {
- echarts = ec;
- var option = {
- graphic: {
- id: 'text1',
- type: 'rect',
- shape: {
- x:0,
- y:0,
- width: 100,
- height: 100,
- },
- style: {
- fill: 'red',
- }
- }
- };
- var myChart = echarts.init(document.getElementById('main'));
- myChart.setOption(option);
- setTimeout(function () {
- // 删除上例中定义的 'text1' 元素。
- myChart.setOption({
- graphic: {
- id: 'text1',
- $action: 'remove'
- }
- });
- // 已经删除,此步应无效。
- // myChart.setOption({
- // graphic: {
- // id: 'text1',
- // $action: 'remove'
- // }
- // });
- // 删除后再添加。
- myChart.setOption({
- id: 'text1',
- type: 'rect',
- shape: {
- x:0,
- y:0,
- width: 100,
- height: 100,
- },
- style: {
- fill: 'red',
- }
- });
- }, 1000);
- var hasRect;
- window.onresize = function() {
- document.getElementById('wid').innerText = window.innerWidth;
- // var option = myChart.getOption();
- var option = {};
- if (window.innerWidth < 600) {
- if (hasRect) {
- option.graphic = { // 删除上例中定义的 'text1' 元素。
- id: 'text1',
- $action: 'remove'
- }
- hasRect = false;
- }
- }
- else {
- option.graphic = {
- id: 'text1',
- type: 'rect',
- shape: {
- x:0,
- y:0,
- width: 100,
- height: 100,
- },
- style: {
- fill: 'red',
- }
- };
- hasRect = true;
- }
- myChart.setOption(option);
- }
- // window.onresize();
- });
- </script>
- </body>
- </html>
|