123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title></title>
- <style type="text/css">
- html,
- body,
- .ui-echarts {
- padding: 0;
- margin: 0;
- overflow: hidden;
- background-color: transparent;
- width: 100%;
- height: 100%;
- }
- .ui-echarts {
- }
- </style>
- </head>
- <body>
- <div class="ui-echarts" id="main" style="width: 100%;width: 100%;"></div>
- <script type="text/javascript" src="./uni.webview.1.5.4.js"></script>
- <script type="text/javascript" src="./echarts.min.js"></script>
-
- <script type="text/javascript">
- let isReady = false;
- let uiChart = null;
-
-
- function setOption (option) {
- if (!uiChart) {
- return;
- }
- uiChart.clear();
- uiChart.setOption(option);
- postMessage({ state: 3 });
- }
-
- function initChart () {
- if (uiChart) {
- return;
- }
- uiChart = echarts.init(document.getElementById('main'));
-
- postMessage({ state: 2 });
- }
-
- function clearChart() {
- if (uiChart) {
- return;
- }
- uiChart.clear();
- postMessage({ state: 5 });
- }
-
- function toImage () {
- const imageStr = uiChart.getDataURL({
-
-
-
- pixelRatio: 2,
- backgroundColor: 'transparent',
-
-
- });
- postMessage({ state: 4, base64: imageStr });
- }
-
- function postMessage (data) {
- if (!isReady) {
- console.error('ui-echarts 未准备就绪');
- return;
- }
- uni.postMessage({ data: data });
- }
- document.addEventListener('UniAppJSBridgeReady', function() {
- isReady = true;
-
- postMessage({ state: 1 });
-
- initChart();
- });
- </script>
- </body>
- </html>
|