123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <template>
- <div shadow="never" class="homeBoxCard" v-loading="loading">
- <br />
- <div class="height300" ref="chainChartRef" />
- <br />
- </div>
- </template>
- <script>
- import { defineComponent, onMounted, ref, watch } from 'vue'
- import * as echarts from 'echarts'
- export default defineComponent({
- name: 'CurveCom',
- props: {
- echartsDataOne: Object,
- },
- setup(props) {
- const chainChartRef = ref(null)
- const resultListDate = ref([])
- // 读取数据 func
- const loading = ref(true)
- const getData = async () => {
- loading.value = false
- var aa = props.echartsDataOne.listDate
- var bb = props.echartsDataOne.listDate2
- console.log(aa)
- console.log(bb)
- if (aa.length > bb.length) {
- resultListDate.value = aa.map(function (index, item) {
- return index + ' / ' + (bb[item] ? bb[item] : '')
- })
- }else{
- resultListDate.value = bb.map(function (index, item) {
- return index + ' / ' + (aa[item] ? aa[item] : '')
- })
- }
-
- console.log('resultListDate.value')
- console.log(resultListDate.value)
- }
- function echarts2() {
- let myChart = echarts.init(chainChartRef.value)
- // 绘制图表
- myChart.setOption({
- color: ['#FEB70D', '#50F335', '#0DC8FE'],
- title: {
- text: props.echartsDataOne.name,
- left: '2.5%',
- textStyle: {
- color: '#9d9d9d',
- fontSize: 14,
- fontWeight: 600,
- },
- },
- tooltip: {
- trigger: 'axis',
- },
- // 图列组件
- legend: {
- itemHeight: 10, //改变圆圈大小
- itemWidth: 26, //改变圆圈大小
- itemGap: 30,
- textStyle: {
- color: 'black',
- },
- left: 'center',
- // bottom: '0',
- },
- toolbox: {
- show: true,
- feature: {
- // dataView: { show: true, readOnly: false },
- // magicType: { show: true, type: ["line", "bar"] },
- // restore: { show: true },
- saveAsImage: {
- show: true,
- color: 'black',
- title: '',
- name: '图表下载',
- },
- },
- iconStyle: {
- borderColor: '#666',
- },
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '5%',
- containLabel: true,
- },
- xAxis: {
- type: 'category',
- boundaryGap: true,
- data: props.echartsDataOne ? resultListDate.value : [],
- axisTick: {
- show: true, //去除刻度线
- },
- // showMinLabel: true,//显示最小值
- showMaxLabel: true,//显示最大值
- // axisLabel:false,
- // axisLabel: {
- // interval:0,
- // rotate:"-12",
- // color: 'black', // 文本颜色
- // },
- axisLine: {
- show: false, // 去除轴线
- },
- },
- yAxis: {
- nameTextStyle: {
- color: 'black',
- fontSize: 10,
- },
- type: 'value',
- axisTick: {
- show: true, //去除刻度线
- },
- axisLabel: {
- color: 'black', // 文本颜色
- },
- axisLine: {
- show: true, // 去除轴线
- lineStyle: {
- color: 'black',
- },
- },
- splitNumber: 5,
- splitLine: {
- show: true,
- lineStyle: {
- color: '#9d9d9d',
- },
- },
- },
- series: [
- {
- name: '本期',
- type: 'line',
- smooth: false,
- data: props.echartsDataOne.list2,
- symbolSize: 6,
- markPoint: {
- data: [
- { type: 'max', name: 'Max' },
- { type: 'min', name: 'Min' },
- ],
- },
- },
- {
- name: '上期',
- type: 'line',
- smooth: false,
- data: props.echartsDataOne.list,
- symbolSize: 6,
- markPoint: {
- data: [
- { type: 'max', name: 'Max' },
- { type: 'min', name: 'Min' },
- ],
- },
- },
- ],
- })
- window.onresize = function () {
- // 自适应大小
- myChart.resize()
- }
- }
- const writeValue = (val) => {
- val
- getData()
- echarts2()
- }
- //监听变化
- watch(
- () => props.echartsDataOne,
- (newVal, oldVal, clear) => {
- // 执行异步任务,并得到关闭异步任务的 id
- // console.log(newVal)
- let id = writeValue(newVal, oldVal)
- // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
- clear(() => clearTimeout(id))
- },
- { lazy: true }
- )
- onMounted(() => {
- getData()
- echarts2()
- })
- return {
- chainChartRef,
- loading,
- echarts,
- resultListDate,
- }
- },
- })
- </script>
- <style lang="scss" scoped>
- .homeBoxCard {
- // margin-bottom: 24px;
- ::v-deep(.el-card__header) {
- padding-left: 12px;
- padding-right: 12px;
- }
- ::v-deep(.el-card__body) {
- padding: 12px;
- font-size: 14px;
- line-height: 1.5715;
- }
- ::v-deep(.el-divider) {
- margin: 8px 0;
- }
- .num {
- font-size: 30px;
- color: #515a6e;
- }
- .height300 {
- height: 15rem;
- }
- }
- </style>
|