194Echarts - 自定义系列(Error Bar on Catesian)
On Error 系列 自定义 bar
2023-09-11 14:15:41 时间
效果图
源代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="js/echarts.min.js"></script>
<script src="js/jquery-1.11.0.min.js"></script>
<script src="dist/extension/dataTool.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 1024px;height:768px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
var option;
var categoryData = [];
var errorData = [];
var barData = [];
var dataCount = 100;
for (var i = 0; i < dataCount; i++) {
var val = Math.random() * 1000;
categoryData.push('category' + i);
errorData.push([
i,
echarts.number.round(Math.max(0, val - Math.random() * 100)),
echarts.number.round(val + Math.random() * 80)
]);
barData.push(echarts.number.round(val, 2));
}
function renderItem(params, api) {
var xValue = api.value(0);
var highPoint = api.coord([xValue, api.value(1)]);
var lowPoint = api.coord([xValue, api.value(2)]);
var halfWidth = api.size([1, 0])[0] * 0.1;
var style = api.style({
stroke: api.visual('color'),
fill: null
});
return {
type: 'group',
children: [{
type: 'line',
shape: {
x1: highPoint[0] - halfWidth, y1: highPoint[1],
x2: highPoint[0] + halfWidth, y2: highPoint[1]
},
style: style
}, {
type: 'line',
shape: {
x1: highPoint[0], y1: highPoint[1],
x2: lowPoint[0], y2: lowPoint[1]
},
style: style
}, {
type: 'line',
shape: {
x1: lowPoint[0] - halfWidth, y1: lowPoint[1],
x2: lowPoint[0] + halfWidth, y2: lowPoint[1]
},
style: style
}]
};
}
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
title: {
text: 'Error bar chart'
},
legend: {
data: ['bar', 'error']
},
dataZoom: [{
type: 'slider',
start: 50,
end: 70
}, {
type: 'inside',
start: 50,
end: 70
}],
xAxis: {
data: categoryData
},
yAxis: {},
series: [{
type: 'bar',
name: 'bar',
data: barData,
itemStyle: {
normal: {
color: '#77bef7'
}
}
}, {
type: 'custom',
name: 'error',
itemStyle: {
normal: {
borderWidth: 1.5
}
},
renderItem: renderItem,
encode: {
x: 0,
y: [1, 2]
},
data: errorData,
z: 100
}]
};
myChart.setOption(option);
</script>
</body>
</html>
相关文章
- spring boot 之 错误:SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap'
- DevOps on DevCloud|代码检查服务如何降低“Billion Dollar Mistake” NPE风险
- 解决org.openqa.selenium.WebDriverException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms org.springframework.beans.BeanInstantiation
- [Ramda] Filter an Array Based on Multiple Predicates with Ramda's allPass Function
- [RxJS] Reactive Programming - Rendering on the DOM with RxJS
- [Java Srping] Configuring embedded Tomcat to run on https (NOT production code)
- [HTML5] Show Images of Differing Resolutions Depending on the Viewport Width with srcset
- [服务器时区问题]PHP Warning: strftime(): It is not safe to rely on the system's timezone set
- HTTP编译安装报错: AH00526: Syntax error on line 167 of /etc/httpd/httpd.conf:
- Error message Exception raised without specific error
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring
- 成功解决Error while trying to retrieve text for error ORA-12154
- Paper:He参数初始化之《Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet C》的翻译与解读
- 成功解决pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 48, saw 2
- 关于appium踩坑 :Encountered internal error running command: Error: Cannot verify the signature of (已解决)
- 解决Failed toString() invocation on an object com.alibaba.fastjson.JSONException: write javaBean error
- 嵌入式linux开发,交叉编译tslib-1.22时报错:configure:13646: error: possibly undefined macro: AC_MSG_ERROR
- Error:java: Compilation failed: internal java compiler error
- nltk安装Wordnet出错[nltk_data] Error loading wordnet: <urlopen error [Errno 111]
- 成功解决ERROR: Could not install packages due to an EnvironmentError: [Errno 28] No space left on device
- Docker出现 Error response from daemon: driver failed programming external connectivity on endpoint 解决
- 【React 错误处理】 ---- Error: Minified React error #185;