Toggle navigation
双Y轴数据显示问题
By
啊我了我了与我
2017-11-30 02:23:43
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
var uploadedDataURL = "/asset/get/s/data-1512008413702-H181j16gM.jpg"; //求大神指点如何实现双Y轴刻度移动到网格线两端,还有数据颜色的变换如何实现? //下面就是双y轴的颜色设置和第一个柱状图的点击变换颜色事件 option = { title: { text: 'Awesome Chart' }, legend: { data: ['降水量', '平均温度'] }, xAxis: [{ type: 'category', data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], axisPointer: { type: 'shadow' } }], yAxis: [{ type: 'value', name: '水量', axisLabel: { formatter: '{value} ml' } }, { type: 'value', name: '温度', min: 0.000000001, //如果使用0,会出现你之前的情况,必须大于0的,使用0.000000001无限接近0 axisLabel: { formatter: function(value, index) { if (index === 0) { //因为最小值不是0,重新赋值0 value = 0; } return value + "℃"; } } }], series: [{ name: '降水量', type: 'bar', // data: [440, 420, 410, 440, 450, 460, 450.6, 430, 420, 410, 455, 432] // data: [440, 420, 410, 440, 450, 460, 450.6, 430, 420, 410, 455, 432] data:[ { value: 440, label: {}, itemStyle:{ normal:{ color : "green", //柱状图的颜色 borderColor : "black", //边框的颜色 borderWidth : 10 //边框宽度 } } }, { value: 420, label: {}, itemStyle:{} }, { value: 410, label: {}, itemStyle:{} }, { value: 440, label: {}, itemStyle:{} }, { value: 450, label: {}, itemStyle:{} }, { value: 460, label: {}, itemStyle:{} }, { value: 450.6, label: {}, itemStyle:{} }, { value: 430, label: {}, itemStyle:{} }, { value: 420, label: {}, itemStyle:{} }, { value: 410, label: {}, itemStyle:{} }, { value: 455, label: {}, itemStyle:{} }, { value: 432, label: {}, itemStyle:{} }, ] }, { name: '平均温度', type: 'line', yAxisIndex: 1, //当只有一个Y轴时,该参数默认为0,且链接的就是一个Y轴;有双轴时,从0 开始,依次累加1。 data: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1] }] }; //点击事件 var array = ["red","orange","green","aqua","blue","purple"],key = 0; //定义颜色和颜色数组下标 myChart.on('click', function (params) { //点击 var myChartOption = myChart.getOption(); //获取echart.option if (params.componentType === 'series') { //判断点击的是否series if (params.seriesIndex === 0) { //判断series的下标 //重新赋值颜色 myChartOption.series[params.seriesIndex].data[params.seriesIndex].itemStyle.normal.color = array[key]; key++; if(key == array.length){ //到了数组长度,循环重新开始 key = 0; } } } myChart.setOption(myChartOption); //初始化echart.option });