chart.js 柱状图效果

发布于 2021-11-23 23:57:11 字数 135 浏览 818 评论 4

chart.js  图表可以做出这种效果吗?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

臻嫒无言 2021-11-25 23:52:16

引用来自“char1st”的评论

我自己弄了下 效果马马虎虎.

<!doctype html>
<html>
	<head>
		<title>Bar Chart</title>
		<script src="../Chart.js"></script>
		<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
		<style>
			canvas{
			}
		</style>
	</head>
	<body>
		<canvas id="canvas" height="200" width="1000"></canvas>
		<canvas width="1000" height="200" id="canvas1" style="margin-top: -50px;"></canvas>

	<script>
	
		var arr=[65,-59,90,-81,56,-55,40];
		var arr1=[65,-59,90,-81,56,-55,40];
	
		 for(var i=0;i<arr.length;i++){
			if(arr[i]<0)
			arr.splice(i,1,0);
		 }
		 for(var i=0;i<arr1.length;i++){
			if(arr1[i]>0)
			arr1.splice(i,1,0);
			else
			arr1.splice(i,1,-arr1[i]);
		 }
		
	
		var barChartData = {
			labels : ["","","","","","",""],
			datasets : [
				{
					fillColor : "rgba(220,220,220,0.5)",
					strokeColor : "rgba(220,220,220,1)",
					data : arr
				}
			]
			
		}

				var barChartData1 = {
			labels : ["","","","","","",""],
			datasets : [
				{
					fillColor : "rgba(220,220,220,0.5)",
					strokeColor : "rgba(220,220,220,1)",
					data : arr1
				}
			]
			
		}
	var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(barChartData);
		var canvas1=document.getElementById("canvas1");
	var context=canvas1.getContext("2d");
	var myLine1 = new Chart(context).Bar(barChartData1);
	 context.translate(0, canvas1.height);
		context.scale(1, -1);
	</script>
	</body>
</html>

累赘 2021-11-25 04:09:32

我自己弄了下 效果马马虎虎.

<!doctype html>
<html>
	<head>
		<title>Bar Chart</title>
		<script src="../Chart.js"></script>
		<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
		<style>
			canvas{
			}
		</style>
	</head>
	<body>
		<canvas id="canvas" height="200" width="1000"></canvas>
		<canvas width="1000" height="200" id="canvas1" style="margin-top: -50px;"></canvas>

	<script>
	
		var arr=[65,-59,90,-81,56,-55,40];
		var arr1=[65,-59,90,-81,56,-55,40];
	
		 for(var i=0;i<arr.length;i++){
			if(arr[i]<0)
			arr.splice(i,1,0);
		 }
		 for(var i=0;i<arr1.length;i++){
			if(arr1[i]>0)
			arr1.splice(i,1,0);
			else
			arr1.splice(i,1,-arr1[i]);
		 }
		
	
		var barChartData = {
			labels : ["","","","","","",""],
			datasets : [
				{
					fillColor : "rgba(220,220,220,0.5)",
					strokeColor : "rgba(220,220,220,1)",
					data : arr
				}
			]
			
		}

				var barChartData1 = {
			labels : ["","","","","","",""],
			datasets : [
				{
					fillColor : "rgba(220,220,220,0.5)",
					strokeColor : "rgba(220,220,220,1)",
					data : arr1
				}
			]
			
		}
	var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(barChartData);
		var canvas1=document.getElementById("canvas1");
	var context=canvas1.getContext("2d");
	var myLine1 = new Chart(context).Bar(barChartData1);
	 context.translate(0, canvas1.height);
		context.scale(1, -1);
	</script>
	</body>
</html>

飘然心甜 2021-11-24 23:48:05

你的想法很好,实现起来有比较难啊。

岁吢 2021-11-24 21:19:21

一个canvas估计不行,你可以把原来的数据拆分成正负2组,分走的空位用0替换,弄2个canvas分别显示,之后负数那组的canvas做镜面垂直翻转。可能还要 css调整下,才能有那个效果。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文