highcharts样式记录

图表设置

const rendChart = (min, max) => {
  Highcharts.setOptions({
    global: { useUTC: false },
  });
  Highcharts.chart('hourly-chart', {
    chart: {
      spacingBottom: 0,
      marginLeft: 53,
      marginTop: 10,
      marginBottom: 0,
      marginRight: 13,
      style: {
        fontSize: '0.2rem',
        color: '#363a44',
        lineHeight: '0.32rem',
        fontWeight: '400',
        fontFamily: 'PingFang SC',
      },
      type: 'spline',
    },
    accessibility: {
      enabled: false,
    },
    title: {
      text: '',
    },
    credits: { enabled: false },
    xAxis: {
      type: 'datetime',
      dateTimeLabelFormats: {
        hour: '%H',
        day: '%d日',
        week: '%m-%d',
        month: '%Y-%m',
        year: '%Y',
      },
      min: min,
      max: max,
      tickInterval: 3600 * 1000 * 3,
      lineWidth: 0,
      gridLineWidth: 0,
      tickWidth: 0,
      labels: {
        enabled: false,
      },
      plotBands: getPlotBands(),
    },
    yAxis: {
      lineWidth: 0,
      gridLineWidth: 0,
      title: {
        text: '',
      },
      labels: {
        align: 'center',
        overflow: 'justify',
        y: 0,
        x: -7,
        formatter: function () {
          return this.value + '℃';
        },
        style: {
          color: '#686B73',
          fontWeight: '400',
          lineHeight: '12px',
          fontSize: '12px',
          textOverflow: 'none',
        },
        zIndex: 10,
      },
    },
    tooltip: {
      backgroundColor: 'rgba(52, 174, 237, 0.9)',
      shadow: false,
      valueSuffix: '',
      useHTML: true,
      margin: 0,
      padding: 0,
      borderRadius: 0,
      formatter: function () {
        return `<div class="tooltip" style="width: 110px;height: 52px;display: flex;flex-direction: column;margin: 0px;padding: 10px;fontSize: 13px;color: #fff;">
          <div style="height: 16px;lineHeight: 16px;backgroundColor: 'rgba(52, 174, 237, 0.9)';">${dayjs(
            this.x
          ).format('M/DD HH')}点</div>
          <div style="height: 16px;lineHeight: 16px;backgroundColor: 'rgba(52, 174, 237, 0.9)';">weather${
            this.y
          }℃</div>
        </div>`;
      },
    },
    legend: {
      enabled: false,
    },
    plotOptions: {
      spline: {
        dataLabels: {
          enabled: true,
          useHTML: true,
          x: 0,
          formatter: function () {
            return `<img class="charts-label" style="display: flex;alignItems: center;width: 20px;height: 20px;" src="${imageUrl(
              `ww/${this.point.ww}.png`
            )}" alt="hourly" />`;
          },
        },
        states: {
          hover: {
            halo: {
              size: 6,
            },
          },
        },
      },
      series: {
        marker: {
          radius: 2,
          width: 1,
          lineWidth: 1,
          borderWidth: 1,
          symbol: 'circle',
        },
      },
    },
    series: [
      {
        name: '实况',
        type: 'spline',
        color: '#FF8F1F',
        yAxis: 0,
        data: hourlyData.value,
        pointWidth: 70,
        marker: {
          enabled: false,
        },
      },
    ],
  });
};

min与max设置

const hourlyDataFormat = (data) => {
  data.value.forEach((item, index) => {
    item.wsl = getWindLevel(item.ws);
    if (index) {
      let before = getWindLevel(data.value[index - 1].ws);
      item.isBefore = before === item.wsl;
    } else item.isBefore = false;
    if (index !== data.value.length - 1) {
      let after = getWindLevel(data.value[index + 1].ws);
      item.isAfter = after === item.wsl;
    } else item.isAfter = false;
    // 温度为null处理
    item.temp = item.temp !== null ? parseFloat(item.temp) : '--';
    item.pr = item.pr !== null ? parseFloat(item.pr) : '--';
    item.x = dayjs(item.t).valueOf();
    item.y = Number(item.temp);
    item.t = dayjs(item.t).get('hour');
    item.ww = parseInt(item.ww).toString();
    item.ww = item.t >= 6 && item.t < 20 ? item.ww.padStart(3, '0') : item.ww.padStart(2, '0');
  });
  let min = data.value[0].x - 3600 * 1000 * 1.5;
  let max = data.value[data.value.length - 1].x + 3600 * 1000 * 1.5;
  nextTick(() => {
    rendChart(min, max);
  });
};

附加样式设置

#hourly-chart {
  height: 1.88rem;
  width: 100%;
  :deep(.charts-label) {
    margin-top: -0.3rem;
    margin-left: -0.2rem;
    position: inherit;
    z-index: 1 !important;
  }
  :deep(.highcharts-tooltip) {
    margin-top: 0.33rem;
    margin-left: 0.05rem;
    span {
      .tooltip {
        position: inherit;
        z-index: 9999 !important;
        background: rgba(52, 174, 237, 0.9);
        border-radius: 0px 55px 55px 24px;
      }
    }
  }
}

plotBands是图表背后分条的样式

const getPlotBands = () => {
  let plotBands = [];
  let colors = ['rgba(243, 245, 249, 1)', 'rgba(255,255,255,1)', 'rgba(52, 174, 237, 0.1)'];
  hourlyData.value.forEach((item, index) => {
    // if (index !== hourlyData.value.length - 1) {
    plotBands.push({
      from: item.x - 3600 * 1000 * 1.5,
      to: item.x + 3600 * 1000 * 1.5,
      color: index === 0 ? colors[2] : colors[index % 2],
    });
    // } else {
    plotBands.push({
      from: item.x,
      to: item.x,
      color: colors[index % 2],
    });
    // }
  });
  console.log(plotBands);
  console.log(hourlyData.value);
  return plotBands;
};
相关推荐
网安-轩逸18 分钟前
IPv4地址表示法详解
开发语言·php
play_big_knife18 分钟前
鸿蒙项目云捐助第二十八讲云捐助项目首页组件云数据库加载轮播图
数据库·华为·harmonyos·鸿蒙·云开发·鸿蒙开发·鸿蒙技术
qq_321665331 小时前
mysql 数据库迁移到达梦数据库
数据库·mysql
Hello.Reader2 小时前
Redis大Key问题全解析
数据库·redis·bootstrap
西猫雷婶4 小时前
python学opencv|读取图像(十九)使用cv2.rectangle()绘制矩形
开发语言·python·opencv
靖顺4 小时前
【OceanBase 诊断调优】—— packet fly cost too much time 的根因分析
数据库·oceanbase
liuxin334455664 小时前
学籍管理系统:实现教育管理现代化
java·开发语言·前端·数据库·安全
码农W4 小时前
QT--静态插件、动态插件
开发语言·qt
ke_wu5 小时前
结构型设计模式
开发语言·设计模式·组合模式·简单工厂模式·工厂方法模式·抽象工厂模式·装饰器模式
code04号5 小时前
python脚本:批量提取excel数据
开发语言·python·excel