echarts图表报错,触发事件重新加载图表时报错

var kpiDataList;
var supplier;
var index;
var analysisQuery = function(){
return {
fillCharInfo:function(xData,seriesData){
var IndexDataChart = echarts.init(document.getElementById('IndexDataChart'));
var option = {
tooltip : {
trigger: 'axis'
},
calculable : true,
xAxis : [
{
type : 'category',
boundaryGap : false,
data : xData
}
],
yAxis : [
{
type : 'value',
axisLabel : {
formatter: '{value}'
}
}
],
grid: {
width: 300,
height: 150,
y: 30,
x: 30,
borderColor: '#fff'
},
series : [
{
name:'指标结果值',
type:'line',
data:seriesData,
markPoint : {
data : [
{type : 'max', name: '最大值'},
{type : 'min', name: '最小值'}
]
},
markLine : {
data : [
{type : 'average', name: '平均值'}
]
}
}
]
};
IndexDataChart.setOption(option);

    },
    /**
     * 查询考核记录排名
     */
    querySupplierScore : function(){
        var timeRange = $("#timeRange").val();
        var params = [];
        params.push({name : 'timeRange', value : timeRange});
        $.ajax({
            type : "POST",
            url : "srm/owner/facade/assessment/getSupplierRank.shtml",
            data : params,
            dataType : "json",
            async:false,
            success : function(data) {
                if (data[0].length > 0) {
                    var dataList = data[0];
                    drawRankChart(dataList);
                    analysisQuery.querySupplierIndex(dataList[0].companyName);
                }
            }
        });
    },
    /**
     * 查询供应商的指标信息分析
     */
    querySupplierIndex : function(supplierName){
        var timeRange = $("#timeRange").val();
        var params = [];
        params.push({name : 'timeRange', value : timeRange});
        params.push({name : 'supplierName', value : supplierName });
        $.ajax({
            type : "POST",
            url : "srm/owner/facade/assessment/getSupplierIndex.shtml",
            data : params,
            dataType : "json",
            async:false,
            success : function(data) {
                if (null != data) {
                    $('#IndexAnalysisChart').empty();
                    var indexNameList = data[0];
                    var indexMaxValueList = data[1];
                    var indexValueList = data[2];
                    kpiDataList = data[3];
                    drawPieChart(indexNameList,indexMaxValueList,indexValueList);
                    if(indexNameList.length > 0){
                        drawLineChart(indexNameList[0]);
                    }
                }
            }
        });
    },
    /**
     * 查询供应商的考核明细
     */
    querySupplierKpiDetail : function(supplierName,indexName){
        var timeRange = $("#detailTimeRange").val();
        var params = [];
        params.push({name : 'timeRange', value : timeRange});
        params.push({name : 'supplierName', value : supplierName });
        params.push({name : 'indexName', value : indexName });
        $.ajax({
            type : "POST",
            url : "srm/owner/facade/assessment/getSupplierKpiDetail.shtml",
            data : params,
            dataType : "json",
            async:false,
            success : function(data) {
                if (null != data) {
                    var list = juicer(tplKpiDetail,data);
                    var totalCount = 0;
                    var totalExceCount = 0;
                    var indexValue = 0;
                    var totalAward = 0;
                    var totalCost = 0;
                    var totalMoney = 0;
                    $("#kpiDetail","#addModal").empty().append(list);
                    var kpiDetailList = data.kpiDetailList;
                    for(var i = 0; i<kpiDetailList.length ;i++){
                        totalCount += parseInt(kpiDetailList[i].lskdTotalCount);
                        totalExceCount += parseInt(kpiDetailList[i].lskdExceptionCount);
                        indexValue += parseInt(kpiDetailList[i].lskdOldValue);
                        totalAward += parseInt(kpiDetailList[i].lskdAwardMoney);
                        totalCost += parseInt(kpiDetailList[i].lskdAmerceMoney);
                    }
                    totalMoney = totalAward-totalMoney;
                    indexValue = indexValue/(kpiDetailList.length);
                }
            }
        });
    }
};

}();
require.config({
paths: {
echarts: 'srm/manage/js/echarts/dist'
}
});
function drawRankChart(data){
require(
[
'echarts',
'echarts/chart/bar' // 使用柱状图就加载bar模块,按需加载
],
function(){
// 基于准备好的dom,初始化echarts图表
var seriesData = [];
var xData = [];
if ('' === data || null === data){
seriesData = [0];
xData = [""];
}else{
if(data.length < 10){
for (var i = 0;i < data.length ; i++){
var supplier = data[i].companyName;
var score = data[i].score;
seriesData.push(score);
xData.push(supplier);
}
}else{
for (var i = 0;i < 10 ; i++){
var supplier = data[i].companyName;
var score = data[i].score;
seriesData.push(score);
xData.push(supplier);
}
}
}
var rankChart = echarts.init(document.getElementById('rankChart'));
var ecConfig = echarts.config;
rankChart.on(ecConfig.EVENT.CLICK, clickBarChart);
rankChart.on(ecConfig.EVENT.DBLCLICK, showKpiDetail);
var colorList = [ '#ff7d93', '#52cdd5', '#7ecef4', '#979ec9' ];
var itemStyle = {
normal : {
color : function(params) {
if (params.dataIndex >= 0 && params.dataIndex < 3) {
// for legend
return colorList[params.dataIndex];
} else {
return colorList[colorList.length - 1];
}
}
}
};
var option = {
tooltip : {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
},
formatter : '{b}
{a0}:{c0}'
},

            calculable : false,
            xAxis : [
                {
                    type : 'category',
                    splitLine: {show: false},
                    axisLabel: {
                        textStyle : {
                            align : 'center'
                    }},
                    data : xData
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    splitLine: {show: false},
                    axisLabel: {show: false},
                    axisLine: {show:false}
                }
            ],
            grid: {
                width: 700,
                height: 170,
                y: 5,
                x: 5,
                borderColor: '#fff'
            },
            series : [
                {
                    name:'分数',
                    clickable : true,
                    type:'bar',
                    stack: '总量',
                    barWidth:40,
                    itemStyle: itemStyle,
                    data:seriesData
                }
            ]
        };

        // 为echarts对象加载数据 
        rankChart.setOption(option); 
    }
);

}

function drawPieChart(indexName,indexMaxValue,indexValue){
require(
[
'echarts',
'echarts/chart/pie'
],
function() {
var indicatorData = [];
for(var i =0 ; i < indexName.length ; i ++){
indicatorData.push({text: indexName[i],max: indexMaxValue[i]});
}
var IndexAnalysisChart = echarts.init(document.getElementById('IndexAnalysisChart'));
var ecConfig = echarts.config;
IndexAnalysisChart.on(ecConfig.EVENT.CLICK, clickPieChart);
IndexAnalysisChart.on(ecConfig.EVENT.DBLCLICK, showKpiIndexDetail);
var option = {
tooltip : {
trigger: 'axis'
},
polar : [
{
indicator : indicatorData
}
],
grid: {
width: 300,
height: 190,
y: 10,
x: 0,
borderColor: '#fff'
},
series : [
{
"symbol":"emptyCircle",//空心节点,
type: 'radar',
data : [
{
value : indexValue,
name : '指标得分'
}
]
}
]
};

// 为echarts对象加载数据
IndexAnalysisChart.setOption(option);
}
);
}

function clickBarChart(param) {

if (typeof param.seriesIndex === 'undefined') {

return;

}

supplier = param.name;
if (param.type === 'click') {

analysisQuery.querySupplierIndex(param.name);
}

}

function clickPieChart(param) {

if (typeof param.seriesIndex === 'undefined') {

return;

}

if (param.type === 'click') {

index = param.name;
var seriesData = [];
var xData = [];
if ('' === kpiDataList || null === kpiDataList){
seriesData = [0];
xData = [""];
return analysisQuery.fillCharInfo(xData,seriesData);
}
for (var i = 0; i < kpiDataList.length; i++) {
if (kpiDataList[i].lskdLepiName === index) {
var time = analysisQuery
.MonthDayFormatHandler(kpiDataList[i].createTime);
var score = kpiDataList[i].lskdOldValue;
seriesData.push(score);
xData.push(time);
}
}
analysisQuery.fillCharInfo(xData,seriesData);
}

}
触发事件重新加载图表时报错:
“_axisList”的值: 对象为 null 或未定义

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问