123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <!--
- * @Author: your name
- * @Date: 2021-10-26 17:53:37
- * @LastEditTime: 2021-11-29 09:29:48
- * @LastEditors: Please set LastEditors
- * @Description: 成本分析柱状图
- * @FilePath: \hyyfScreen\src\views\Production\board\ChartCostLine.vue
- -->
- <template>
- <div class="cost-histogram">
- <div id="costHistogram"></div>
- </div>
- </template>
- <script>
- export default {
- props: {
- data: {
- type: Array,
- default: () => [],
- },
- xAxisData: {
- type: Array,
- default: () => [],
- },
- },
- data() {
- return {
- myChart: null,
- };
- },
- methods: {
- init() {
- const commonSeriesItem = {
- name: "Forest",
- type: "bar",
- barGap: 0,
- emphasis: {
- focus: "series",
- },
- };
- let seriesData = [
- {
- ...commonSeriesItem,
- name: "公摊成本",
- color: "rgb(112,182,3)",
- data: [],
- },
- {
- ...commonSeriesItem,
- name: "兽药成本",
- color: "rgb(0,215,233)",
- data: [],
- },
- {
- ...commonSeriesItem,
- name: "饲料成本",
- color: "rgb(255,255,160)",
- data: [],
- },
- ];
- this.data.forEach((item) => {
- seriesData[0].data.push(item.gtValue);
- seriesData[1].data.push(item.syValue);
- seriesData[2].data.push(item.slValue);
- });
- let options = {
- // title: {
- // text: '存栏变动',
- // x: 10,
- // y: 0
- // },
- tooltip: {
- trigger: "axis",
- // formatter: (value) => {
- // return value + "元";
- // },
- },
- // legend: {
- // data: ['头']
- // },
- // color: ['#3aa0ff', '#4dcb73', '#fad337', '#f2637b', '#975fe4'],
- grid: {
- left: "3%",
- right: "4%",
- bottom: "3%",
- containLabel: true,
- },
- xAxis: [
- // {
- // type: "value",
- // name: "元",
- // boundaryGap: [0, 0.01],
- // axisPointer: {
- // type: "shadow",
- // },
- // axisLine: {
- // show: true,
- // lineStyle: {
- // color: "#6e7079",
- // },
- // },
- // axisTick: {
- // show: false,
- // },
- // },
- {
- type: "category",
- axisTick: {
- show: false,
- },
- axisPointer: {
- type: "none",
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: "#fff",
- },
- },
- data: this.xAxisData,
- },
- ],
- //[
- yAxis: {
- // type: "category",
- // inverse: true,
- // axisLabel: {
- // // formatter: '{value} °C'
- // show: true
- // },
- // axisLine: {
- // show: true,
- // lineStyle: {
- // color: '#6e7079',
- // }
- // },
- axisTick: {
- show: false,
- },
- // splitLine:{
- // show:false
- // }
- axisLine: {
- show: true,
- lineStyle: {
- color: "#fff",
- },
- },
- type: "value",
- name: "元",
- },
- // {
- // type: 'value',
- // name: '湿度',
- // axisLabel: {
- // formatter: '{value} RH'
- // },
- // axisLine: {
- // show: false,
- // lineStyle: {
- // color: '#6e7079',
- // }
- // },
- // axisTick:{
- // show:false
- // },
- // // splitLine:{
- // // show:false
- // // }
- // }
- //],
- // dataset: [
- // {
- // dimensions: ['num'],
- // source: [
- // [32541],
- // [82467],
- // [54363],
- // [64642],
- // [40257],
- // [95422]
- // ]
- // },
- // {
- // transeform: {
- // type: 'sort',
- // config: {
- // dimension: 'num',
- // order: 'desc'
- // }
- // }
- // }
- // ],
- series: seriesData,
- };
- const _this = this;
- this.myChart.setOption(options);
- this.myChart.on("click", function(param) {
- _this.$emit("changeCostIndex", param.dataIndex);
- });
- },
- },
- mounted() {
- this.myChart = this.$echarts.init(document.getElementById("costHistogram"));
- // this.init();
- },
- watch: {
- data(value) {
- console.log("成本分析柱状图数据", value);
- this.init();
- },
- },
- };
- </script>
- <style scoped>
- .cost-histogram {
- width: 90%;
- height: 50%;
- }
- #costHistogram {
- width: 100%;
- height: 100%;
- }
- </style>
|