123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <!-- 圆柱柱状图 -->
- <template>
- <div>
- <boxTop :title="title" />
- <div class="oblongBox">
- <div class="chartsdom" id="cylindrical"></div>
- </div>
- </div>
- </template>
- <script>
- import boxTop from '@/components/boxTop/index.vue'
- export default {
- data() {
- return {
- option: null,
- information: {},
- }
- },
- components: {
- boxTop,
- },
- props: {
- barWidth: {
- type: Number,
- },
- area: {
- type: Array,
- },
- dataArray: {
- type: Array,
- },
- title: {
- type: String,
- default: ``,
- },
- unit: {
- type: String,
- },
- },
- mounted() {
- this.getEchart()
- },
- watch: {
- dataArray() {
- this.getEchart()
- },
- },
- methods: {
- getEchart() {
- let myChart = echarts.init(document.getElementById(`cylindrical`))
- this.information = {
- barWidth: 10,
- colorArray: {
- lineColor: `rgba(199,214,242, 0.2)`,
- labelColor: ` #c7d6f2`,
- },
- unit: this.unit,
- area: this.area,
- dataArray: this.dataArray,
- }
- this.option = {
- // animation: false, //去除加载时缓动动画
- tooltip: {
- trigger: `axis`,
- backgroundColor: `rgba(0, 0, 0, 0.8)`,
- textStyle: {
- color: `#fff`,
- },
- axisPointer: {
- lineStyle: {
- color: `transparent`,
- },
- },
- formatter: function (params) {
- console.log(params, `111111`)
- return [params[0].value].join(`<br>`)
- },
- },
- xAxis: {
- axisLine: {
- lineStyle: {
- color: this.information.colorArray.lineColor,
- },
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- color: this.information.colorArray.labelColor,
- fontSize: 12,
- margin: 15,
- interval: 0,
- },
- splitLine: {
- show: true,
- interval: this.information.area.length,
- lineStyle: {
- color: this.information.colorArray.lineColor,
- width: 1,
- },
- },
- data: this.information.area,
- },
- grid: {
- left: `6%`,
- right: `6%`,
- bottom: `8%`,
- top: `24%`,
- containLabel: true,
- },
- yAxis: [
- {
- type: `value`,
- name: this.information.unit,
- nameTextStyle: {
- color: `#65ABE7`,
- fontSize: 12,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: this.information.colorArray.lineColor,
- width: 2,
- },
- },
- axisLabel: {
- margin: 20,
- color: this.information.colorArray.labelColor,
- fontSize: 12,
- fontWeight: 4,
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: this.information.colorArray.lineColor,
- width: 2,
- },
- },
- },
- ],
- series: [
- {
- name: this.information.unit,
- tooltip: {
- show: true,
- },
- type: `bar`,
- barWidth: this.information.barWidth, // 柱子宽度
- label: {
- show: false,
- position: `top`,
- padding: 10,
- fontSize: 20,
- color: `#00ffff`,
- fontWeight: `bold`,
- },
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- {
- offset: 0,
- color: `#47FEED`,
- },
- {
- offset: 1,
- color: `#0E7E7D`,
- },
- ]),
- },
- data: this.information.dataArray,
- legendHoverLink: false,
- },
- {
- // 柱子底部椭圆
- name: `报修数量`,
- tooltip: {
- show: false,
- },
- type: `pictorialBar`,
- itemStyle: {
- // 未填充部分鼠标移上去颜色
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- {
- offset: 0,
- color: `#1ABFC0`,
- },
- {
- offset: 1,
- color: `#1ABFC0`,
- },
- ]),
- },
- symbolRotate: 0,
- symbolSize: [this.information.barWidth, 5],
- symbolOffset: [0, 3],
- symbolPosition: `start`,
- data: this.information.dataArray,
- z: 3,
- },
- {
- // 柱子头部椭圆
- name: `报修数量`,
- tooltip: {
- show: false,
- },
- type: `pictorialBar`,
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- {
- offset: 0,
- color: `#1ABFC0`,
- },
- {
- offset: 1,
- color: `#1ABFC0`,
- },
- ]),
- },
- symbolRotate: 0,
- symbolSize: [this.information.barWidth, 5],
- symbolOffset: [0, -3],
- symbolPosition: `end`,
- data: this.information.dataArray,
- z: 3,
- },
- ],
- }
- myChart.setOption(this.option, true)
- },
- },
- beforeDestroy() {},
- }
- </script>
- <style lang="less" scoped>
- .oblongBox {
- width: 401px;
- height: 275px;
- .chartsdom {
- width: 100%;
- height: 100%;
- }
- }
- </style>
|