ECharts.测试02

1、"ECharts.测试01" 里面使用的是 文档[doc]中的"模块化单文件引入(推荐)"方式。

  本例子 使用的是 文档[doc]中的"标签式单文件引入",目前开来,还是 这个方式 方便一点

  缺点:"模块化单文件引入(推荐)" 是要什么再加载什么,网络传输文件较少;"标签式单文件引入" 是将整套东西一起传到客户端了,传输的文件较大

  优点:方便,编程难度也较低

  1.1、源码修改自 "E:\ZC_IDE\JavaScript_3rd\echarts-2.2.7\doc\example\www2\..."

    (1)、去掉了 地图部分

    (2)、静态显示,改成 可以动态变化

2、代码:

  2.1、代码中使用的插件 echarts-2.2.7,来自 "E:\ZC_IDE\JavaScript_3rd\echarts-2.2.7 (1).zip"

    是从"E:\ZC_IDE\JavaScript_3rd\echarts-2.2.7\build\source\echarts-all.js" copy过来的

  2.2、

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
</head>

<body>
    <!--点击下面的按钮,动态的改变柱状图的信息-->
    <input type="button" value="testBtn" onclick="TestBtnClick()"/>

    <!--Step:1 Prepare a dom for ECharts which (must) has size (width & hight)-->
    <!--Step:1 为ECharts准备一个具备大小(宽高)的Dom-->
    <div id="main" style="height:500px;border:1px solid #ccc;padding:10px;"></div>
    <div id="mainMap" style="height:500px;border:1px solid #ccc;padding:10px;"></div>

    <!--Step:2 Import echarts-all.js-->
    <!--Step:2 引入echarts-all.js-->
    <script src="js/echarts-all.js"></script>
    
    <script type="text/javascript">
        // Step:3 echarts & zrender as a Global Interface by the echarts-plain.js.
        // Step:3 echarts和zrender被echarts-plain.js写入为全局接口
        var g_ecChart = echarts.init(document.getElementById('main'));
        var g_ecOption =
        {
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:['蒸发量','降水量']
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    splitArea : {show : true}
                }
            ],
            series : [
                {
                    name:'蒸发量',
                    type:'bar',
                    data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
                },
                {
                    name:'降水量',
                    type:'bar',
                    data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
                }
            ]
        };// g_ecOption
        g_ecChart.setOption(g_ecOption);
        
        function TestBtnClick()
        {
            console.log("g_ecOption.series(02) : "+g_ecOption.series);

            var series = [];
            var series01 = 
                {
                    name:'蒸发量',
                    type:'bar',
                    data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
                };
            var series02 = 
                {
                    name:'降水量',
                    type:'bar',
                    data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 1182.2, 48.7, 18.8, 6.0, 2.3]
                };
            series[0] = series01;
            series[1] = series02;

            g_ecChart.setOption(g_ecOption);// 方式三 (官方文档是保存的是回调函数里面的_ec[如上面的 方式二],我这里保存的是 g_ecChart)
            g_ecChart.setSeries(series);

            console.log("g_ecOption.series(03) : "+g_ecOption.series);
        }
    </script>
</body>
</html>

 

3、

4、

5、

 

转载于:https://www.cnblogs.com/H5UI/p/8482184.html

我的代码是这样子的:<Echart :options="options" id="rightTopChart" class="echarts_bottom" ref="rightTopChart" ></Echart> <script> import * as echarts from "echarts"; import "echarts-gl/dist/echarts-gl"; const register3D = () => { try { // 现代版本注册方式 if (echarts.registerGL) { const echartsGL = require("echarts-gl/dist/echarts-gl"); echarts.registerGL(echartsGL); } // 兼容旧版 else if (window.echarts && window.echarts.registerExtension) { window.echarts.registerExtension(require("echarts-gl/dist/echarts-gl")); } } catch (e) { console.error("3D注册失败:", e); // 降级方案 echarts.registerSeries("pie3D", { type: "pie3D", init: function () {}, }); } }; register3D(); export default { data() { return { options: {}, optionsRig: {}, consultation: 200, // 咨询 reportForRepair: 70, // 报修 svVolume: "54", // SV报修量 pcVolume: "25", // pc报修量 }; }, computed: {}, created() {}, mounted() { this.init(); }, methods: { init() { this.options = { series: [ { type: "pie3D", shape: "ring", radius: ["30%", "70%"], height: 15, data: [ { value: 172, name: "咨询数量", itemStyle: { color: "#0085FD" } }, { value: 79, name: "报修数量", itemStyle: { color: "#FFA500" } }, ], viewControl: { distance: 150, autoRotate: true, }, }, ], };,其中 Echart的具体代码为:<!-- * @Author: daidai * @Date: 2022-02-28 16:29:08 * @LastEditors: Please set LastEditors * @LastEditTime: 2022-09-27 15:05:45 * @FilePath: \web-pc\src\pages\big-screen\components\echart\index.vue --> <template> <div :id="id" :class="className" :style="{ height: height, width: width }" /> </template> <script> import * as echarts from 'echarts'; export default { name: 'echart', props: { className: { type: String, default: 'chart' }, id: { type: String, default: 'chart' }, width: { type: String, default: '100%' }, height: { type: String, default: '100%' }, options: { type: Object, default: ()=>({}) } }, data () { return { chart: null } }, watch: { options: { handler (options) { // 设置true清空echart缓存 this.chart.setOption(options, true) }, deep: true } }, mounted () { this.initChart(); }, beforeDestroy () { this.chart.dispose() this.chart = null }, methods: { initChart () { // 初始化echart this.chart = echarts.init(this.$el) this.chart.setOption(this.options, true) } } } </script> <style> </style> , 但是在页面上仍然报错[ECharts] Unknown series pie3D 在vue2中书写修改
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值