做漫画网站,wordpress 去掉图片链接,竞价推广开户公司,黄石网站建设哪家好图表组件
ECharts#xff0c;全称为Enterprise Charts#xff0c;是一个使用JavaScript实现的开源可视化库。它主要用于数据可视化领域#xff0c;能够方便地创建出直观、交互性强的图表。ECharts由百度团队开发#xff0c;目前是Apache的顶级项目之一。ECharts支持的图表…图表组件
ECharts全称为Enterprise Charts是一个使用JavaScript实现的开源可视化库。它主要用于数据可视化领域能够方便地创建出直观、交互性强的图表。ECharts由百度团队开发目前是Apache的顶级项目之一。ECharts支持的图表类型非常丰富包括但不限于柱状图、折线图、饼图、散点图、雷达图、地图、热力图、树图、桑基图等多种。ECharts的设计哲学是可高度定制化和拓展性好能够满足多种数据可视化需求。
ECharts的主要特点
Echarts官方链接
丰富的图表类型ECharts提供了丰富的图表类型能够满足大部分数据可视化需求。高度可定制用户可以通过配置项自定义图表的各个元素如色彩、字体、样式等满足个性化展示需求。良好的交互性ECharts支持图表的交互操作如缩放、拖拽、点击等提高用户体验。强大的性能利用zrender作为渲染引擎优化渲染算法即使是大数据量也能保证较好的性能。多端适应支持基于HTML5的Web标准可在PC和移动设备上使用。国际化ECharts支持多国语言方便国际化项目使用。
安装命令如下
cd bingo_web # 注意客户端安装模块的所有命令务必在package.json所在目录下操作。
npm config set strict-ssl true
npm install echarts --save --registryhttps://registry.npm.taobao.org安装完成以后直接可以在src/views/Bingo.vue页面组件中进行使用Echarts基本示例查看效果。 你遇到的错误信息 Initialize failed: invalid dom. 指示 ECharts 试图在一个无效的 DOM 元素上进行初始化。这个问题通常是因为在试图初始化 ECharts 实例的时候对应的 DOM 元素还没有被渲染或不可见导致 ECharts 无法找到这个元素。
在你的代码中的以下部分
var myChart echarts.init(document.getElementById(main));你试图使用 document.getElementById(main) 来获取 DOM 元素但在 Vue 应用中并不存在一个 idmain 的元素。另外由于你使用了 Vue 组合式API (script setup 标签)直接操作 DOM 可能不是最佳实践。
为了解决这个问题并且以 Vue 的方式来正确地使用 ECharts你可以按照以下步骤来修改你的代码
步骤 1: 使用 Vue 引用来访问 DOM 元素
首先使用 Vue 的 ref 来创建一个引用而不是使用 document.getElementById。你已经为 div 元素创建了一个引用 echartsDom
div refechartsDom stylewidth: 600px; height: 400px;/div步骤 2: 在合适的生命周期钩子中初始化 ECharts
由于直接在 script setup 中执行代码可能会在 DOM 元素准备好之前尝试访问它们因此你需要确保在 DOM 元素可用时初始化 ECharts 实例。在 Vue 3 中你可以使用 onMounted 钩子来保证 DOM 已经挂载
import { onMounted, ref } from vue;const echartsDom ref(null); // 创建一个 refonMounted(() {if (echartsDom.value) {var myChart echarts.init(echartsDom.value);// 指定图表的配置项和数据var option {// 配置项...};// 使用刚指定的配置项和数据显示图表。myChart.setOption(option);}
});注意在使用组合式 API 时通过 ref 创建的引用在模板中使用时不需要 .value但在 JavaScript 中访问时需要通过 .value 来获取其真实的 DOM 元素。
完整的修改建议
根据上述步骤修改后你的 script setup 部分应该类似于这样
import { onMounted, ref } from vue;
import * as echarts from echarts;
// 其他 import...const echartsDom ref(null);onMounted(() {if (echartsDom.value) {var myChart echarts.init(echartsDom.value);var option {title: {text: ECharts入门示例},tooltip: {},xAxis: {data: [衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子]},yAxis: {},series: [{name: 销量,type: bar,data: [5, 20, 36, 10, 10, 20]}]};myChart.setOption(option);}
});并在 template 部分相应地更新 echartsDom ref 的使用
div refechartsDom stylewidth: 600px; height: 400px;/div执行效果
例子2
templateh1 classtimeTime/h1divdiv classc1ConfigProvider :localezhCN!-- 应用的其他内容 --diva-button typeprimary clickshowModalOpen Modal/a-buttona-modal v-model:openopen titleBasic Modal okhandleOka-form:modelformStatenamebasic:label-col{ span: 8 }:wrapper-col{ span: 16 }autocompleteofffinishonFinishfinishFailedonFinishFaileda-form-itemlabelUsernamenameusername:rules[{ required: true, message: Please input your username! }]a-input v-model:valueformState.username //a-form-itema-form-itemlabelPasswordnamepassword:rules[{ required: true, message: Please input your password! }]a-input-password v-model:valueformState.password //a-form-itema-form-item nameremember :wrapper-col{ offset: 8, span: 16 }a-checkbox v-model:checkedformState.rememberRemember me/a-checkbox/a-form-itema-form-item :wrapper-col{ offset: 8, span: 16 }a-button typeprimary html-typesubmitSubmit/a-button/a-form-item/a-form/a-modal/diva-calendar v-model:valuevalue panelChangeonPanelChange selectonSelect/a-calendarrouter-view//ConfigProvider/divdiv classc2div refechartsDom stylewidth: 600px; height: 400px;/div/divdiv classc3div classchart refchart/div/divdiv classc4 !-- 在HTML中指定一个容器用来容纳将要绘制的图表 --div classdrak refdark/div/div/div/templatescript setupimport * as echarts from echarts;import { ConfigProvider } from ant-design-vue;import zhCN from ant-design-vue/es/locale/zh_CN;import {onMounted, ref} from vue;const open ref(false);const showModal () {open.value true;};const handleOk e {console.log(e);open.value false;};import { reactive } from vue;const formState reactive({username: ,password: ,remember: true,});const onFinish values {console.log(Success:, values);};const onFinishFailed errorInfo {console.log(Failed:, errorInfo);};const value ref();const onPanelChange (value, mode) {console.log(value, mode);};const echartsDom ref(null);/*饼图*/const chart ref(null)let setbing () {//基于准备好的dom初始化echarts实例const myChart1 echarts.init(chart.value);var option1;option1 {legend: {top: bottom},toolbox: {show: true,feature: {mark: { show: true },dataView: { show: true, readOnly: false },restore: { show: true },saveAsImage: { show: true }}},series: [{name: Nightingale Chart,type: pie,radius: [50, 250],center: [50%, 50%],roseType: area,itemStyle: {borderRadius: 8},data: [{ value: 40, name: rose 1 },{ value: 38, name: rose 2 },{ value: 32, name: rose 3 },{ value: 30, name: rose 4 },{ value: 28, name: rose 5 },{ value: 26, name: rose 6 },{ value: 22, name: rose 7 },{ value: 18, name: rose 8 }]}]};//使用刚指定的配置项和数据显示图表。option1 myChart1.setOption(option1);}/*3d图*/const dark ref()let ditu () {var myChart2 echarts.init(dark.value);var option2;option2 {title: {text: Proportion of Browsers,subtext: Fake Data,top: 10,left: 10},tooltip: {trigger: item},legend: {type: scroll,bottom: 10,data: (function () {var list [];for (var i 1; i 28; i) {list.push(i 2000 );}return list;})()},visualMap: {top: middle,right: 10,color: [red, yellow],calculable: true},radar: {indicator: [{ text: IE8-, max: 400 },{ text: IE9, max: 400 },{ text: Safari, max: 400 },{ text: Firefox, max: 400 },{ text: Chrome, max: 400 }]},series: (function () {var series [];for (var i 1; i 28; i) {series.push({type: radar,symbol: none,lineStyle: {width: 1},emphasis: {areaStyle: {color: rgba(0,250,0,0.3)}},data: [{value: [(40 - i) * 10,(38 - i) * 4 60,i * 5 10,i * 9,(i * i) / 2],name: i 2000 }]});}return series;})()};option2 myChart2.setOption(option2);}onMounted(() {if (echartsDom.value) {var myChart echarts.init(echartsDom.value);var option {title: {text: ECharts入门示例},tooltip: {},xAxis: {data: [衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子]},yAxis: {},series: [{name: 销量,type: bar,data: [5, 20, 36, 10, 10, 20]}]};myChart.setOption(option);}setbing()ditu()});/scriptstyle scoped.events {list-style: none;margin: 0;padding: 0;}.events .ant-badge-status {overflow: hidden;white-space: nowrap;width: 100%;text-overflow: ellipsis;font-size: 12px;}.notes-month {text-align: center;font-size: 28px;}.notes-month section {font-size: 28px;}.chart{width: 500px;height: 500px;float: left;margin: 0 auto 0 100px;}.c1,.c2,.c3,.c4 {float: left;}.drak{width: 300px;height: 500px;float: left;margin: 0 auto 0 100px;}/style实现效果 文章转载自: http://www.morning.jpbpc.cn.gov.cn.jpbpc.cn http://www.morning.gwkjg.cn.gov.cn.gwkjg.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.feites.com.gov.cn.feites.com http://www.morning.qtnmp.cn.gov.cn.qtnmp.cn http://www.morning.wpydf.cn.gov.cn.wpydf.cn http://www.morning.bxczt.cn.gov.cn.bxczt.cn http://www.morning.dhbyj.cn.gov.cn.dhbyj.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.ktfnj.cn.gov.cn.ktfnj.cn http://www.morning.bnylg.cn.gov.cn.bnylg.cn http://www.morning.jrqw.cn.gov.cn.jrqw.cn http://www.morning.plhyc.cn.gov.cn.plhyc.cn http://www.morning.hhfqk.cn.gov.cn.hhfqk.cn http://www.morning.glswq.cn.gov.cn.glswq.cn http://www.morning.tfznk.cn.gov.cn.tfznk.cn http://www.morning.fywqr.cn.gov.cn.fywqr.cn http://www.morning.rkfgx.cn.gov.cn.rkfgx.cn http://www.morning.ctxt.cn.gov.cn.ctxt.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.lmknf.cn.gov.cn.lmknf.cn http://www.morning.tqpnf.cn.gov.cn.tqpnf.cn http://www.morning.pclgj.cn.gov.cn.pclgj.cn http://www.morning.mymz.cn.gov.cn.mymz.cn http://www.morning.mmzfl.cn.gov.cn.mmzfl.cn http://www.morning.fmswb.cn.gov.cn.fmswb.cn http://www.morning.lhsdf.cn.gov.cn.lhsdf.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn http://www.morning.gbxxh.cn.gov.cn.gbxxh.cn http://www.morning.jfbbq.cn.gov.cn.jfbbq.cn http://www.morning.nswcw.cn.gov.cn.nswcw.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.zwtp.cn.gov.cn.zwtp.cn http://www.morning.qgjxy.cn.gov.cn.qgjxy.cn http://www.morning.kmkpm.cn.gov.cn.kmkpm.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.ynstj.cn.gov.cn.ynstj.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.nrbcx.cn.gov.cn.nrbcx.cn http://www.morning.bkjhx.cn.gov.cn.bkjhx.cn http://www.morning.wmlby.cn.gov.cn.wmlby.cn http://www.morning.rnpnn.cn.gov.cn.rnpnn.cn http://www.morning.ghxtk.cn.gov.cn.ghxtk.cn http://www.morning.zbjfq.cn.gov.cn.zbjfq.cn http://www.morning.rpwht.cn.gov.cn.rpwht.cn http://www.morning.trkl.cn.gov.cn.trkl.cn http://www.morning.yrbq.cn.gov.cn.yrbq.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.kwqt.cn.gov.cn.kwqt.cn http://www.morning.sgcdr.com.gov.cn.sgcdr.com http://www.morning.zdnrb.cn.gov.cn.zdnrb.cn http://www.morning.wskn.cn.gov.cn.wskn.cn http://www.morning.lpbrp.cn.gov.cn.lpbrp.cn http://www.morning.mjmtm.cn.gov.cn.mjmtm.cn http://www.morning.wqrdx.cn.gov.cn.wqrdx.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.hzqjgas.com.gov.cn.hzqjgas.com http://www.morning.xsklp.cn.gov.cn.xsklp.cn http://www.morning.npmcf.cn.gov.cn.npmcf.cn http://www.morning.rgmd.cn.gov.cn.rgmd.cn http://www.morning.kljhr.cn.gov.cn.kljhr.cn http://www.morning.wspyb.cn.gov.cn.wspyb.cn http://www.morning.hqgkx.cn.gov.cn.hqgkx.cn http://www.morning.ssjee.cn.gov.cn.ssjee.cn http://www.morning.sftrt.cn.gov.cn.sftrt.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.touziyou.cn.gov.cn.touziyou.cn http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn http://www.morning.nytgk.cn.gov.cn.nytgk.cn http://www.morning.hxcuvg.cn.gov.cn.hxcuvg.cn http://www.morning.rrgqq.cn.gov.cn.rrgqq.cn http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn http://www.morning.ljdd.cn.gov.cn.ljdd.cn http://www.morning.qbmpb.cn.gov.cn.qbmpb.cn http://www.morning.knrgb.cn.gov.cn.knrgb.cn http://www.morning.dqrpz.cn.gov.cn.dqrpz.cn http://www.morning.jjxxm.cn.gov.cn.jjxxm.cn http://www.morning.ypjjh.cn.gov.cn.ypjjh.cn http://www.morning.rwlnk.cn.gov.cn.rwlnk.cn