ageChart.vue 3.11 KB
<template>
	<view class="agechart">
		<div :id='bindId' class="chart">
			<div class="titles">{{chartData.title}}</div>
			<div class="agesBox">
				<div class="items">
					<circles
					  radius="8"
					  :progress="maleBarPer"
					  :num="maleNum"
					  barColor="#3BB8FF"
					  backgroundColor="#F3F3F3"
					  textColor="#3BB8FF"
					  :picSrc="pic1"
					  :isAnimation="false"
					></circles>
				</div>
				<div class="items">
					<circles
					  radius="8"
					  :progress="femaleBarPer"
					  :num="femaleNum"
					  barColor="#FFC62E"
					   textColor="#FFC62E"
					   :picSrc="pic2"
					  backgroundColor="#F3F3F3"
					  :isAnimation="false"
					></circles>
				</div>
			</div>
			<div class="barBox">
				<div class="bar">
					<div class="maleBar" :style="{width:malePer}"></div>
					<div class="femaleBar" :style="{width:femalePer}"></div>
				</div>
				<span class="barText maleText">{{malePer}}</span>
				<span  class="barText femaleText">{{femalePer}}</span>
			</div>
		</div>
	</view>
</template>

<script>
	import boyPic from "../static/index/boy.png"
	import girlPic from "../static/index/girl.png"
	import circles from './circle.vue'
	export default {
	  data () {
		return {
			pic1:boyPic,
			pic2:girlPic,
			malePer:'0%',
			femalePer:'0%',
			maleBarPer:0,
			femaleBarPer:0,
			maleNum:0,
			femaleNum:0
		}
	  },
	  mounted() {
	  },
	  watch:{
		  bindId:function(newValue,oldValue){
		  },
		  chartData:{
			handler(newValue,oldValue){
				this.drawLine();
			},
			deep:true
		  },
	  },
	  components:{
	  	circles
	  },
	  props:{
			bindId:{
				type:String,
				default:''
			},
		   chartData: {
                type: Object,
                default: function(){
					return {}
				}
            }
	  },
	  methods: {
	  	 drawLine() {
			 this.maleNum=this.chartData.series[0].data[0].value;
			 this.femaleNum=this.chartData.series[0].data[1].value;
			 var allNum=this.maleNum+this.femaleNum;
				this.maleBarPer=parseInt(this.maleNum/allNum*100);
				this.femaleBarPer=100-this.maleBarPer;
				this.malePer=this.maleBarPer+'%';
				this.femalePer=this.femaleBarPer+'%';
		 }
	  }
	}
</script>

<style>
	.barBox{
		margin: 0 auto;
		display: block;
		position: relative;
		width: 487.31upx;
		top: 50.72upx;
	}
	.chart{
		width:706.52upx;
		height:449.27upx;
		background: #FFFFFF;
		margin: 0 auto;
		margin-bottom: 18.2upx;
		border-radius:7.24upx;
		overflow: hidden;
		padding-top: 12.68upx;
	}
	.titles{
		padding-left: 25.36upx;
		font-weight: "normal";
		font-size: 25.36upx;
		color: '#4A4A4A'
	}
	.agesBox{
		display: inline-flex;
		flex-direction: row;
		width: 100%;
		padding: 56.15upx 54.34upx 0 54.34upx;
	}
	.items{
		flex:1;
	}
	.bar{
		width: 487.31upx;
		background: #F3F3F3;
		height: 10.86upx;
		border-radius:5.43upx;
		overflow: hidden;
	}
	.maleBar{
		float: left;
		background: #3BB8FF;
		height: 100%;
		width: 32%;
	}
	.femaleBar{
		float: left;
		background: #FFC62E;
		height: 100%;
		width: 68%;
	}
	.barText{
		position: absolute;
		top: 18.11upx;
		font-size:25.36upx;
		color:rgba(74,74,74,1);
	}
	.femaleText{
		color:  #FFC62E;
		right: 0;
	}
	.maleText{
		color: #3BB8FF;
	}
</style>