echarts-line,根据数据控制颜色,绘制一条多颜色的线条
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了echarts-line,根据数据控制颜色,绘制一条多颜色的线条相关的知识,希望对你有一定的参考价值。
参考技术A fn1()var myChart = echarts.init(document.getElementById(divId));
var data = [];
var timeData = [];
var yMinData = -5;
var yMaxData= 5
for(var i =0 ; i < nowData.length ; i++)
if(parseInt(nowData[i].ERROR) > parseInt(yMaxData))
yMaxData = parseInt(nowData[i].ERROR)
else if(parseInt(nowData[i].ERROR) < parseInt(yMinData))
yMinData = parseInt(nowData[i].ERROR)
data.push(nowData[i].ERROR);
timeData.push(nowData[i].COLLECTINGTIME);
option =
toolbox: //增加保存,切换图表功能
show: true,
right: '5%',
feature:
saveAsImage:
show:true,
excludeComponents :['toolbox'],
pixelRatio: 2
,
magicType:
type: ['line', 'bar']
,
xAxis:
type: 'category',
data: timeData,
name: '时间'
,
title:
show: true,
text: titleName,
left: 'center',
,
tooltip:
trigger: 'axis'
,
legend:
data:[name],
left:'middle',
top:'bottom',
,
yAxis:
type: 'value',
max: yMaxData,
min: yMinData,
name: '相对误差(%)',
,
series: [
name:name,
lineStyle:
normal:
width: 2,
type: 'dashed'
,
itemStyle:
normal:
borderWidth: 3,
color: 'red'
,
data: data,
type: 'line',
symbol: 'triangle',
symbolSize: 20,
markLine:
lineStyle:
normal:
color:'red'
,
data: [
yAxis: 5, name: '平均值',
yAxis: -5, name: '111'
]
,
],
visualMap: [ //改变线的颜色
show: true,
dimension: 1,
type:'piecewise',
right: '1%',
top: '6%',
pieces: [min: 5, max: yMaxData, color: 'red', label: '不合格', min: yMinData, max: -5, color: 'red', label: '不合格', min: -5, max: 5, color: 'green', label: '合格'], //pieces的值由动态数据决定
outOfRange:
color: 'green',
symbol: 'triangle',
],
;
myChart.setOption(option);
如何根据第三列绘制具有不同颜色的线图? (KeyError:0)
我有一个数据框
Company Id ON/OFF Level of Fuel
DateTime
2018-08-18 00:00:10 25750275 1 82.048
2018-08-18 00:00:39 25750275 1 82.048
2018-08-18 00:01:09 25750275 1 79.936
2018-08-18 00:01:39 25750275 1 79.600
2018-08-18 00:02:10 25750275 1 78.480
[我想要的是在x轴上具有DateTime索引,在y轴上具有“公司ID”的线图,并且该线应根据[ON?OFF]列中的值[0,1 ]。
从seaborn documentation,我尝试调用以下函数
sns.catplot(x=data.index, y="Level of Fuel", hue="ON/OFF",
palette="ON": 1, "OFF": 0,
markers=["^", "o"], linestyles=["-", "--"],
kind="point",data=data)
但是我得到的KeyError:0
的踪迹如下
KeyError Traceback (most recent call last)
<ipython-input-91-cf07ea2f9cbf> in <module>
2 palette="ON": 1, "OFF": 0,
3 markers=["^", "o"], linestyles=["-", "--"],
----> 4 kind="point",data=data)
~/.local/lib/python3.6/site-packages/seaborn/categorical.py in catplot(x, y, hue, data, row, col, col_wrap, estimator, ci, n_boot, units, seed, order, hue_order, row_order, col_order, kind, height, aspect, orient, color, palette, legend, legend_out, sharex, sharey, margin_titles, facet_kws, **kwargs)
3729 # so we need to define ``palette`` to get default behavior for the
3730 # categorical functions
-> 3731 p.establish_colors(color, palette, 1)
3732 if kind != "point" or hue is not None:
3733 palette = p.colors
~/.local/lib/python3.6/site-packages/seaborn/categorical.py in establish_colors(self, color, palette, saturation)
301 else:
302 levels = self.hue_names
--> 303 palette = [palette[l] for l in levels]
304
305 colors = color_palette(palette, n_colors)
~/.local/lib/python3.6/site-packages/seaborn/categorical.py in <listcomp>(.0)
301 else:
302 levels = self.hue_names
--> 303 palette = [palette[l] for l in levels]
304
305 colors = color_palette(palette, n_colors)
KeyError: 0
答案
如果! Keyerrors显示为“ palette”,您可能以错误的方式构建了字典:零不是键而是值,因此它是 palette=0 : "OFF", 1 : "ON"
以上是关于echarts-line,根据数据控制颜色,绘制一条多颜色的线条的主要内容,如果未能解决你的问题,请参考以下文章