qq_32535067 2018-07-27 03:12 采纳率: 0%
浏览 1272
已结题

chart柱状图显示乱序customData的每组柱字顺序和我给的数据不一致

var yearCount = result.legend.length;
var categoryCount = result.category.length;

                                var xAxisData = result.category;
                                var customData = [];
                                var legendData = [];
                                var dataList = [];

                                legendData.push('trend');
                                var encodeY = [];
                                for (var i = 0; i < yearCount; i++) {
                                    legendData.push(result.legend[i]);
                                    dataList.push([]);

// customData.push(result.series[i].listData);
encodeY.push(1 + i);
}

                                for (var i = 0; i < categoryCount; i++) {

// xAxisData.push('category' + i);
var customVal = [i];
customData.push(customVal);

// var data = dataList[0];
for (var j = 0; j < dataList.length; j++) {
dataList[j].push(result.series[i].listData[j]);
customVal.push(result.series[i].listData[j]);
}
}

                                function renderItem(params, api) {
                                    var xValue = api.value(0);
                                    var currentSeriesIndices = api.currentSeriesIndices();
                                    var barLayout = api.barLayout({
                                        barGap: '30%', barCategoryGap: '20%', count: currentSeriesIndices.length - 1
                                    });

                                    var points = [];
                                    for (var i = 0; i < currentSeriesIndices.length; i++) {
                                        var seriesIndex = currentSeriesIndices[i];
                                        if (seriesIndex !== params.seriesIndex) {
                                            var point = api.coord([xValue, api.value(seriesIndex)]);
                                            point[0] += barLayout[i - 1].offsetCenter;
                                            point[1] -= 20;
                                            points.push(point);
                                        }
                                    }
                                    var style = api.style({
                                        stroke: api.visual('color'),
                                        fill: null
                                    });

                                    return {
                                        type: 'polyline',
                                        shape: {
                                            points: points
                                        },
                                        style: style
                                    };
                                }

                                option = {
                                    tooltip: {
                                        trigger: 'axis'
                                    },
                                    legend: {
                                        data: legendData
                                    },

// dataZoom: [{
// type: 'slider',
// start: 50,
// end: 70
// }, {
// type: 'inside',
// start: 50,
// end: 70
// }],
xAxis: {
data: xAxisData
},
yAxis: {},
series: [{
type: 'custom',
name: 'trend',
renderItem: renderItem,
itemStyle: {
normal: {
borderWidth: 2
}
},
encode: {
x: 0,
y: encodeY
},
data: customData,
z: 100
}].concat(echarts.util.map(dataList, function (data, index) {
console.log(data);
console.log("legendData[index + 1] "+legendData[index + 1]);
return {
type: 'bar',
animation: false,
name: legendData[index + 1],
itemStyle: {
normal: {
opacity: 0.5
}
},
data: data
};

                                    }))
                                }; 

                                                                    console.log打印出来 数据顺序对着 ,谁知道为什么乱了 ![图片说明](https://img-ask.csdn.net/upload/201807/27/1532661125_387304.png)
  • 写回答

1条回答

  • 0c4d 2018-07-27 08:29
    关注

    截图吧,估计你这是因为文字标题过长,就是每个柱状对应的文字过长,导致图标错位,解决办法,文字变短,或者加宽图表

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试