我想使用数据字段来更改特定香料的线条颜色。就像它为1时一样,它应该是绿色,而当它为2时它应该是黄色。此代码段仅更改数据点的颜色,而不更改线的颜色?有没有机会用echarts存档?
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0/echarts.min.js"></script>
</head>
<body>
<div id="main_chart" style="width: 1200px;height:600px;"></div>
<script type="text/javascript">
// based on prepared DOM, initialize echarts instance
var myChart = echarts.init(document.getElementById('main_chart'));
var app = {};
option = null;
option = {
xAxis: {
type: 'category',
data: ['2012-03-01 05:06', '2012-03-01 05:07', '2012-03-01 05:08', '2012-03-01 05:09', '2012-03-01 05:10', '2012-03-01 05:11']
},
yAxis: {
type: 'value'
},
visualMap: {
show: false,
dimension: 2,
pieces: [
{
lt: 2,
gt: 0,
color: 'green'
}, {
gte: 2,
color: 'red'
}
]
},
series: [{
data: [[1,37,1],[2,36,1],[3,36,2]],
type: 'line',
areaStyle: {}
}]
};
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
</script>
</body>
</html>
答案 0 :(得分:3)
尝试以下示例
1)您应该使用正确的尺寸(xAxis,yAxis),有关更多信息,请阅读文档
2)如果要对整个区域进行着色,请从areaStyle中删除颜色:“海蓝宝石”,然后将其按部件配置进行着色
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0/echarts.min.js"></script>
</head>
<body>
<div id="main_chart" style="width: 1200px;height:600px;"></div>
<script type="text/javascript">
// based on prepared DOM, initialize echarts instance
var myChart = echarts.init(document.getElementById('main_chart'));
var app = {};
option = null;
option = {
xAxis: {
type: 'category',
data: ['2012-03-01 05:06', '2012-03-01 05:07', '2012-03-01 05:08', '2012-03-01 05:09', '2012-03-01 05:10', '2012-03-01 05:11']
},
yAxis: {
type: 'value'
},
visualMap: {
show: false,
dimension: 0,
pieces: [
{
lt: 2,
gt: 0,
color: 'green'
}, {
gt: 2,
lt: 3,
color: 'red'
}, {
gte: 3,
color: 'yellow'
}
]
},
series: [{
data: [[1,37,1],[2,36,1],[3,36,2],[4,38,2]],
type: 'line',
areaStyle: {color: "aquamarine"}
}]
};
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
</script>
</body>
</html>