Code Monkey home page Code Monkey logo

Comments (20)

xlsdg avatar xlsdg commented on May 17, 2024

导入顺序错了,应该是:

import IEcharts from 'vue-echarts-v3/src/full.vue'
import 'echarts/theme/xtheme.js'

<IEcharts
  theme="xtheme"
  :option="bar"
  :resizable="true"
></IEcharts>

from vue-echarts-v3.

M1YT avatar M1YT commented on May 17, 2024

我这边调整了顺序,还是无效,这边应用的应该是默认的echarts样式,换成官方shine等相关主题也是无效
qq 20170727094444

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

官方包里没有 xtheme

image

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024
import IEcharts from 'vue-echarts-v3/src/full.vue';
import 'echarts/theme/macarons.js';

<IECharts
  :option="option"
  theme="macarons"
/>

from vue-echarts-v3.

M1YT avatar M1YT commented on May 17, 2024

xtheme.js是我自己导入的一个自定义的主题,我换成macarons也是无效的
qq 20170727100506

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

检查一下代码,我这边 demo 是可以生效的。

from vue-echarts-v3.

M1YT avatar M1YT commented on May 17, 2024

你的echarts及vue版本,还有系统是啥?
qq 20170727101711

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

package.json:

{
  "name": "echarts-demo",
  "version": "1.0.0",
  "description": "A Vue.js project",
  "author": "xLsDg <[email protected]>",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js",
    "lint": "eslint --ext .js,.vue src"
  },
  "dependencies": {
    "vue": "^2.3.3",
    "vue-echarts-v3": "^1.0.4",
    "vue-router": "^2.3.1"
  },
  "devDependencies": {
    "autoprefixer": "^6.7.2",
    "babel-core": "^6.22.1",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.2.10",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "babel-register": "^6.22.0",
    "chalk": "^1.1.3",
    "connect-history-api-fallback": "^1.3.0",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "eslint": "^3.19.0",
    "eslint-friendly-formatter": "^2.0.7",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-html": "^2.0.0",
    "eslint-config-standard": "^6.2.1",
    "eslint-plugin-promise": "^3.4.0",
    "eslint-plugin-standard": "^2.0.1",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.14.1",
    "extract-text-webpack-plugin": "^2.0.0",
    "file-loader": "^0.11.1",
    "friendly-errors-webpack-plugin": "^1.1.3",
    "html-webpack-plugin": "^2.28.0",
    "http-proxy-middleware": "^0.17.3",
    "webpack-bundle-analyzer": "^2.2.1",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "opn": "^4.0.2",
    "optimize-css-assets-webpack-plugin": "^1.3.0",
    "ora": "^1.2.0",
    "rimraf": "^2.6.0",
    "url-loader": "^0.5.8",
    "vue-loader": "^12.1.0",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.3.3",
    "webpack": "^2.6.1",
    "webpack-dev-middleware": "^1.10.0",
    "webpack-hot-middleware": "^2.18.0",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

echarts.vue:

<template>
  <div class="echarts">
    <IEcharts
      :option="line"
      @ready="onReady"
      theme="macarons"
    />
  </div>
</template>

<script>
  import IEcharts from 'vue-echarts-v3/src/full.vue'
  import 'echarts/theme/macarons.js'

  export default {
    name: 'view',
    components: {
      IEcharts
    },
    props: {
    },
    data () {
      const that = this
      return {
        data: [],
        timer: null,
        now: +new Date(1997, 9, 3),
        oneDay: 24 * 3600 * 1000,
        value: Math.random() * 1000,
        line: {
          title: {
            text: '动态数据 + 时间坐标轴'
          },
          tooltip: {
            trigger: 'axis',
            formatter: function (params) {
              params = params[0]
              var date = new Date(params.name)
              return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' : ' + params.value[1]
            },
            axisPointer: {
              animation: false
            }
          },
          xAxis: {
            type: 'time',
            splitLine: {
              show: false
            }
          },
          yAxis: {
            type: 'value',
            boundaryGap: [0, '100%'],
            splitLine: {
              show: false
            }
          },
          series: [{
            name: '模拟数据',
            type: 'line',
            showSymbol: false,
            hoverAnimation: false,
            data: that.data
          }]
        }
      }
    },
    methods: {
      onReady (instance) {
        const that = this
        that.chart = instance
      },
      randomData () {
        const that = this
        that.now = new Date(+that.now + that.oneDay)
        that.value = that.value + Math.random() * 21 - 10
        return {
          name: that.now.toString(),
          value: [
            [that.now.getFullYear(), that.now.getMonth() + 1, that.now.getDate()].join('/'),
            Math.round(that.value)
          ]
        }
      }
    },
    beforeMount () {
      const that = this
      for (var i = 0; i < 1000; i++) {
        that.data.push(that.randomData())
      }
    },
    mounted () {
      const that = this
      if (that.timer) {
        clearInterval(that.timer)
        that.timer = null
      }
      that.timer = setInterval(function () {
        for (var i = 0; i < 5; i++) {
          that.data.shift()
          that.data.push(that.randomData())
        }

        that.chart && that.chart.setOption({
          series: [{
            data: that.data
          }]
        })
      }, 1000)
    },
    beforeDestroy () {
      const that = this
      if (that.timer) {
        clearInterval(that.timer)
        that.timer = null
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .echarts {
    width: 400px;
    height: 400px;
  }
</style>

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

默认主题:
image

macarons 主题:
image

from vue-echarts-v3.

M1YT avatar M1YT commented on May 17, 2024

_20170727103127

我这边直接复制了你的代码,貌似还是不成功

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

所以说要检查你自己的工程代码配置。

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

demo 演示:

第一步:

$ git clone https://github.com/xlsdg/vue-echarts-v3.git vue-echarts

第二步:

修改 vue-echarts/index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>vue-echarts-v3</title>
    <style type="text/css">
      .echart {
        width: 600px;
        height: 400px;
        border: 1px solid #000;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <button @click="doLoading">Random</button>
      </div>
      <div class="echart" :style="style">
        <i-echarts :option="bar" :loading="loading" :resizable="true" @ready="onReady" @click="onClick" theme="macarons"></i-echarts>
      </div>
    </div>
    <!-- built files will be auto injected -->
  </body>
</html>

第三步:

修改 vue-echarts/src/dev.js

import Vue from 'vue';
import IEcharts from './full.vue';
// import IEcharts from './lite.vue';
// import 'echarts/lib/chart/bar';
// import IEcharts from '../dist/js/full.js';
import 'echarts/theme/macarons.js';

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: {
    IEcharts
  },
  data: () => ({
    loading: true,
    style: {},
    bar: {
      title: {
        text: 'ECharts 入门示例'
      },
      tooltip: {},
      xAxis: {
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
      },
      yAxis: {},
      series: [{
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
      }]
    }
  }),
  methods: {
    doLoading() {
      const that = this;
      let data = [];
      for (let i = 0, min = 5, max = 99; i < 6; i++) {
        data.push(Math.floor(Math.random() * (max + 1 - min) + min));
      }
      that.loading = !that.loading;
      that.bar.series[0].data = data;
      that.style = {
        width: Math.floor(Math.random() * (1024 + 1 - 400) + 400) + 'px',
        height: Math.floor(Math.random() * (768 + 1 - 200) + 200) + 'px'
      };
    },
    onReady(ins) {
      console.dir(ins);
    },
    onClick(event, instance, echarts) {
      console.log(arguments);
    }
  }
});

第四步:

$ cd vue-echarts && npm i && npm run start

浏览器访问 http://localhost:8080/,看看是不是这个效果:

image

from vue-echarts-v3.

ruanzy avatar ruanzy commented on May 17, 2024

我的也是这样
报错:
Uncaught Error: Cannot find module "echarts/theme/macarons.js"

from vue-echarts-v3.

byc1990 avatar byc1990 commented on May 17, 2024

@xlsdg 您好, 我下载了demo, 用官方带的那几个是可以的,但是自定义的就不行, 报错Echarts is not loaded, 把我自定义的放到echarts 源码目录下theme文件夹内是可以的, 请问有没有办法解决?谢谢!

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 17, 2024

@byc1990 把主题单独做成一个 npm 包试试呢?类似这样 https://github.com/xlsdg/nezha-echarts-theme

from vue-echarts-v3.

byc1990 avatar byc1990 commented on May 17, 2024

@xlsdg 好的, 后面试试,多谢回复!

from vue-echarts-v3.

WormGirl avatar WormGirl commented on May 17, 2024

@byc1990 我也是同样的问题 怎么解决

from vue-echarts-v3.

M1YT avatar M1YT commented on May 17, 2024

@WormGirl 我这边上了新版,就可以了

from vue-echarts-v3.

WormGirl avatar WormGirl commented on May 17, 2024

@xf0rk 我用的是最新版本,放在自己的util文件夹里就不可以,必须放到nodemoudles里的echarts 的theme里

from vue-echarts-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.