0

我想知道如何在 Echarts 上导入模块化包?我已在此链接中阅读了他们的文档,

Echarts 文档

但我仍然不知道该怎么做,我必须把那个代码放在哪里?

require.config({
packages: [
    {
        name: 'echarts',
        location: '../../src',
        main: 'echarts'
    },
    {
        name: 'zrender',
        location: '../../../zrender/src', 
        main: 'zrender'
    }
]
});

这是我图表的代码:

var option = {
tooltip : {
    trigger: 'axis'
},
legend: {
    data:['a','b']
},
toolbox: {
    show : true,
    feature : {
        mark : {show: true},
        dataView : {readOnly:false},
        magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
        restore : {show: true},
        saveAsImage : {show: true}
    }
},
calculable : true,
dataZoom : {
    show : true,
    realtime : true,
    start : 40,
    end : 60
},
xAxis : [
    {
        type : 'category',
        boundaryGap : true,
        data : ['sorong','papua','banjarmasin']
    }
],
yAxis : [
    {
        type : 'value'
    }
],
series : [

    {
        name:'b',
        type:'bar',
        data:[23,34,56]
    }
]
};

var ecConfig = require('echarts/config');
function eConsole(param) {
    var mes = '';
    if (typeof param.seriesIndex != 'undefined') {
    window.open("/"+param.name, '_blank');
    win.focus(); 
}
if (param.type == 'hover') {
    document.getElementById('hover-console').innerHTML = 'Event Console : ' + mes;
}
else {
    document.getElementById('console').innerHTML = mes;
}
console.log(param);
}

return myChart.setOption(option).on(ecConfig.EVENT.CLICK, eConsole);
4

1 回答 1

0

您应该看到文档下方的文本。

//from echarts example

... <script src="./js/echarts.js"></script> <script type="text/javascript"> require.config({ paths: { echarts: './js/dist' } }); require( [ 'echarts', 'echarts/chart/line', // load-on-demand, don't forget the Magic switch type. 'echarts/chart/bar' ], function (ec) { var myChart = ec.init(document.getElementById('main')); var option = { ... } myChart.setOption(option); } ); </script>

于 2016-07-27T16:34:51.477 回答