折线图根据拐点值显示不同颜色

<template>
  <div style="margin-top: 100px;">
    <div
      style="width: 600px; height: 180px;margin: auto;"
      id="main1"
    ></div>
    <div
      style="width: 600px; height: 180px;margin: auto;"
      id="main2"
    ></div>
    <div
      style="width: 600px; height: 180px;margin: auto;"
      id="main3"
    ></div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  mounted () {
    this.init1()
    this.init2()
    this.init3()
    window.handleClick = this.formatter
    window.isShow = false; // 假设这是全局变量
  },
  methods: {
    formatter () {
      console.log(", ticket, callback:");
      window.isShow = !window.isShow
    },
    init1 () {
      var chartDom = document.getElementById('main1');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: 'Temperature Change in the Coming Week',
          left: 'center'
        },
        // 设置canvas内部表格的内距
        grid: {
          x: 20,
          y: 40,
          x2: 20,
          y2: 10,
          borderWidth: 5
        },
        tooltip: {
          trigger: 'item',
          triggerOn: 'mousemove',
          enterable: true,
          backgroundColor: 'white',
          formatter: function (arg, ticket, callback) {
            console.log(arg, "arg")
            var options = ['1', '2'] // 假设arg是一个对象,其中包含一个名为options的数组,用于存储自定义选项
            var selectOptions = '';
            for (var i = 0; i < options.length; i++) {
              selectOptions += '<option value="' + options[i] + '">' + options[i] + '</option>';
            }
            var res = `
            <div style="color:black;width: 200px;height: 180px;  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2), -5px 5px 10px rgba(0, 0, 0, 0.2);border-radius:5px;padding:5px">
              <div style="font-weight:bold;color:black">2011/07/24 00:00:00</div>
              <div style="color:black;margin-top:3px">判别结果:1.777777</div>
              <div style="color:black;margin-top:3px">判别结果:1.777777</div>
              <div style="color:black;margin-top:3px">处理后:1.777777</div>
              <span >相差标识:</span>
              <select onchange="handleClick()" style="display: inline-block;width:60px;height:25px;background-color: white;border: 1px solid #D3D3D3 ;color:black;padding:3px;border-radius:2px;text-align:center;line-height:20px">
                ${selectOptions}
              </select>
              <div style="margin-top:8px">
                <div  id="button"></div>
                <div style="display: inline-block;width:60px;height:25px;background-color: rgb(55, 178, 158);border-color: rgb(55, 178, 158);color:white;padding:3px;border-radius:2px;text-align:center;line-height:20px" onclick="handleClick()">
                  ${window.isShow ? '保存' : '编辑'}
                </div>
                <div style="margin-left:10px;display: inline-block;width:60px;height:25px;background-color: white;border: 1px solid #D3D3D3 ;color:black;padding:3px;border-radius:2px;text-align:center;line-height:20px" onclick="handleClick()">
                  取消
                </div>
              <div>
            </div>
            `
            return res
          }
        },
        legend: {},
        toolbox: {
          show: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
          show: false // 设置 x 轴不显示
        },
        yAxis: {
          type: 'value',
          name: '',
          min: -10, // 设置 y 轴最小值
          max: 10   // 设置 y 轴最大值
        },
        splitArea: {
          show: true
        },
        series: [
          {
            name: '',
            type: 'line',
            data: [0, 1, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0],
            smooth: true,
            itemStyle: {
              normal: {
                color: function (params) {
                  return params.data > 1 ? 'red' : 'black';
                },  // 拐点边框颜色
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    },
    init2 () {
      var chartDom = document.getElementById('main2');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: 'Temperature Change in the Coming Week',
          left: 'center'
        },
        // 设置canvas内部表格的内距
        grid: {
          x: 20,
          y: 30,
          x2: 20,
          y2: 10,
          borderWidth: 5
        },
        tooltip: {
          trigger: 'item',
          triggerOn: 'mousemove',
          enterable: true,
          backgroundColor: 'white',
          formatter: function (arg, ticket, callback) {
            var options = ['1', '2'] // 假设arg是一个对象,其中包含一个名为options的数组,用于存储自定义选项
            var selectOptions = '';
            for (var i = 0; i < options.length; i++) {
              selectOptions += '<option value="' + options[i] + '">' + options[i] + '</option>';
            }
            var res = `
            <div style="color:black;width: 200px;height: 180px;  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2), -5px 5px 10px rgba(0, 0, 0, 0.2);border-radius:5px;padding:5px">
              <div style="font-weight:bold;color:black">2011/07/24 00:00:00</div>
              <div style="color:black;margin-top:3px">:1.777777</div>
              <div style="color:black;margin-top:3px">判别结果:1.777777</div>
              <div style="color:black;margin-top:3px">处理后:1.777777</div>
              <span >相差标识:</span>
              <select onchange="handleClick()" style="display: inline-block;width:60px;height:25px;background-color: white;border: 1px solid #D3D3D3 ;color:black;padding:3px;border-radius:2px;text-align:center;line-height:20px">
                ${selectOptions}
              </select>
              <div style="margin-top:8px">
                <div  id="button"></div>
                <div style="display: inline-block;width:60px;height:25px;background-color: rgb(55, 178, 158);border-color: rgb(55, 178, 158);color:white;padding:3px;border-radius:2px;text-align:center;line-height:20px" onclick="handleClick()">
                  ${window.isShow ? '保存' : '编辑'}
                </div>
                <div style="margin-left:10px;display: inline-block;width:60px;height:25px;background-color: white;border: 1px solid #D3D3D3 ;color:black;padding:3px;border-radius:2px;text-align:center;line-height:20px" onclick="handleClick()">
                  取消
                </div>
              <div>
            </div>
            `
            return res
          }
        },
        legend: {},
        toolbox: {
          show: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
          show: false // 设置 x 轴不显示
        },
        yAxis: {
          type: 'value',
          name: '',
          min: -10, // 设置 y 轴最小值
          max: 10   // 设置 y 轴最大值
        },
        splitArea: {
          show: true
        },
        series: [
          {
            name: '',
            type: 'line',
            data: [-5, 2, 5, 0, -2, -5, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0],
            smooth: true,
            itemStyle: {
              normal: {
                color: function (params) {
                  return params.data > 1 ? 'red' : 'black';
                },  // 拐点边框颜色
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    },
    init3 () {
      var chartDom = document.getElementById('main3');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: 'Temperature Change in the Coming Week',
          left: 'center'
        },
        // 设置canvas内部表格的内距
        grid: {
          x: 20,
          y: 30,
          x2: 20,
          y2: 20,
          borderWidth: 5
        },
        tooltip: {
          trigger: 'item',
          triggerOn: 'mousemove',
          enterable: true,
          backgroundColor: 'white',
          formatter: function (arg, ticket, callback) {
            var options = ['1', '2'] // 假设arg是一个对象,其中包含一个名为options的数组,用于存储自定义选项
            var selectOptions = '';
            for (var i = 0; i < options.length; i++) {
              selectOptions += '<option value="' + options[i] + '">' + options[i] + '</option>';
            }
            var res = `
            <div style="color:black;width: 200px;height: 180px;  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2), -5px 5px 10px rgba(0, 0, 0, 0.2);border-radius:5px;padding:5px">
              <div style="font-weight:bold;color:black">2011/07/24 00:00:00</div>
              <div style="color:black;margin-top:3px">:1.777777</div>
              <div style="color:black;margin-top:3px">判别结果:1.777777</div>
              <div style="color:black;margin-top:3px">处理后:1.777777</div>
              <span >相差标识:</span>
              <select onchange="handleClick()" style="display: inline-block;width:60px;height:25px;background-color: white;border: 1px solid #D3D3D3 ;color:black;padding:3px;border-radius:2px;text-align:center;line-height:20px">
                ${selectOptions}
              </select>
              <div style="margin-top:8px">
                <div  id="button"></div>
                <div style="display: inline-block;width:60px;height:25px;background-color: rgb(55, 178, 158);border-color: rgb(55, 178, 158);color:white;padding:3px;border-radius:2px;text-align:center;line-height:20px" onclick="handleClick()">
                  ${window.isShow ? '保存' : '编辑'}
                </div>
                <div style="margin-left:10px;display: inline-block;width:60px;height:25px;background-color: white;border: 1px solid #D3D3D3 ;color:black;padding:3px;border-radius:2px;text-align:center;line-height:20px" onclick="handleClick()">
                  取消
                </div>
              <div>
            </div>
            `
            return res
          }
        },
        legend: {},
        toolbox: {
          show: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value',
          name: '',
          min: -10, // 设置 y 轴最小值
          max: 10   // 设置 y 轴最大值
        },
        splitArea: {
          show: true
        },
        series: [
          {
            name: '',
            type: 'line',
            data: [0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0, 2, 0, -2, 0],
            smooth: true,
            itemStyle: {
              normal: {
                color: function (params) {
                  return params.data > 1 ? 'red' : 'black';
                },  // 拐点边框颜色
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }
};
</script>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值