admin管理员组

文章数量:1345075

I installed using NPM, echarts library in this way

npm install echarts --save

Following the documentation I wrote in my code

import * as echarts from 'echarts'

then I tried a very simple example

const $chart = $('#chart')
let myChart = echarts.init($chart)
const option = {
  title: {
    text: 'ECharts entry example'
  },
  tooltip: {},
  legend: {
    data: ['Sales']
  },
  xAxis: {
    data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks']
  },
  yAxis: {},
  series: [
    {
      name: 'Sales',
      type: 'bar',
      data: [5, 20, 36, 10, 10, 20]
    }
  ]
}
myChart.setOption(option)

but I got this error

ReferenceError: __DEV__ is not defined

What do you think is the problem? I can't find documentation about this error...

I installed using NPM, echarts library in this way

npm install echarts --save

Following the documentation I wrote in my code

import * as echarts from 'echarts'

then I tried a very simple example

const $chart = $('#chart')
let myChart = echarts.init($chart)
const option = {
  title: {
    text: 'ECharts entry example'
  },
  tooltip: {},
  legend: {
    data: ['Sales']
  },
  xAxis: {
    data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks']
  },
  yAxis: {},
  series: [
    {
      name: 'Sales',
      type: 'bar',
      data: [5, 20, 36, 10, 10, 20]
    }
  ]
}
myChart.setOption(option)

but I got this error

ReferenceError: __DEV__ is not defined

What do you think is the problem? I can't find documentation about this error...

Share Improve this question edited Mar 2, 2020 at 11:55 Shark Lasers 4717 silver badges15 bronze badges asked Nov 9, 2017 at 8:37 michoprogrammermichoprogrammer 1,1992 gold badges18 silver badges48 bronze badges 3
  • Seems to be an issue at the moment : see github./efe/echarts/issues/6111, github./efe/echarts/issues/6987, – DarkUrse Commented Nov 9, 2017 at 9:58
  • @DarkUrse there is no solution? I tried to modify the webpack confing without results... – michoprogrammer Commented Nov 9, 2017 at 14:21
  • 1 Honestly I tried to set this __DEV__ flag in the environment.*.ts to see by adding it to window object `window['__DEV__'] = false; to replace this undefined by a boolean as they are doing at the top of their config.js. But no dice. – DarkUrse Commented Nov 9, 2017 at 14:37
Add a ment  | 

5 Answers 5

Reset to default 2

This worked for me (echarts 4.2.1): import * as echarts from 'echarts';

I have import echarts as below and it works

import * as echarts from 'echarts/dist/echarts.js';
  import * as echarts from 'echarts/lib/echarts'
  import 'echarts/lib/chart/line'
  import 'echarts/lib/chart/bar'
  import 'echarts/lib/ponent/tooltip'
  import 'echarts/lib/ponent/title'
  import 'echarts/lib/ponent/legend'

This CDN works for me. Place the script in HTML file in the.

<script src="https://cdnjs.cloudflare./ajax/libs/echarts/4.1.0/echarts-en.mon.min.js"></script>

Old thread, but stumbled upon this when having a similar problem, hoping someone in the future may see this aswell:

I just had the error: Error: Renderer 'undefined' is not imported. Please import it first.

The Problem at the end was, that i was using

import * as echarts from 'echarts';

but also

import { EChartsOption, SeriesOption } from 'echarts';

The second line was throwing everything off. So use the "namespace" echarts and dont import anything other than * as echarts.

本文标签: javascripteCharts import does not work Fails with DEV is not definedStack Overflow