数据可视化【highchart】——散点图

基本案例
在这里插入图片描述
基于案例修改后效果图如下:
在这里插入图片描述
在这里插入图片描述
代码:

<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <style>
    .container {
      width: 600px;
      margin: 20px auto;
      padding: 20px;
      box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5);
      border-radius: 12px;
      text-align: center;
    }
    h1 {
      border-bottom: 3px solid #000;
      padding-bottom: 12px;
    }
  </style>
  <body>
    <div class="container">
      <h1>身高 - 体重</h1>
      <div id="highchart"></div>
    </div>
  </body>
  <script src="./js/jquery.min.js"></script>
  <script src="./js/highcharts.js"></script>
  <script>
    let option = {
      title: null,
      colors: ["pink"],
      chart: {
        type: "scatter",
        zoomType: "xy",
        marginTop: 30,
        marginLeft: 33,
        marginRight: 30,
      },
      xAxis: {
        title: {
          text: "身高",
          align: "high",
          offset: 0,
          x: 30,
          y: -14,
        },
        startOnTick: true,
        endOnTick: true,
        showLastLabel: true,
        lineColor: "#000",
        lineWidth: 1,
        gridLineColor: "#e6e6e6",
        gridLineWidth: 1,
        tickPositioner: function () {
          return [100, 125, 150, 175, 200];
        },
      },
      yAxis: {
        title: {
          enabled: true,
          align: "high",
          offset: 0,
          text: "CPU",
          rotation: 0,
          y: -12,
          x: 20,
        },
        floor: 0,
        ceiling: 100,
        lineColor: "#000",
        lineWidth: 1,
        gridLineColor: "#e6e6e6",
        gridLineWidth: 1,
      },
      legend: {
        enabled: false,
      },
      credits: {
        enabled: false,
      },
      tooltip: {
        pointFormat: "身高:{point.x}<br/>体重: {point.y}<br/>",
      },
      series: [
        {
          name: "身高-体重",
          data: [],
        },
      ],
      plotOptions: {
        scatter: {
          marker: {
            radius: 5,
          },
        },
      },
    };
    $(function () {
    
      let num = 400 + Math.round(Math.random() * 700);
      for (let i = 0; i < num; i++) {
        let newX = 101 + Math.round(Math.random() * 99);
        let newY = 10 + Math.round(Math.random() * 99);
        option.series[0].data[i] = { x: newX, y: newY };
      }
      $("#highchart").highcharts(option);
    });
  </script>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

脑公公

您的鼓励将是我前进的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值