首页 > 其他分享 >ZingChart绘制错误信息面积图

ZingChart绘制错误信息面积图

时间:2024-05-28 09:44:26浏览次数:11  
标签:false text chrome84 ZingChart 错误信息 visible let backgroundColor 绘制

  • 代码案例
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>ZingSoft Demo</title>
  <script nonce="undefined" src="https://cdn.zingchart.com/zingchart.min.js"></script>
  <style>
    #chrome50Overall,
    #chrome50Detail {
      /* min-height: 400px; */
      opacity: 0;
      transition: opacity .3s;
    }
    #chrome84Overall {
      width: 450px;
      height: 500px;
    }
    #chrome84Detail {
      width: 300px;
      height: 500px;
    }

    #chrome50Overall.loaded,
    #chrome50Detail.loaded {
      opacity: 1;
    }

    #chrome84Overall, #chrome84Detail{
      float: left;
      margin-left: 5px;
    }
    #inputs{
      position: absolute;
      top: 50px;
      left: 360px;
    }

    /* #inputs {
      background: #f7f7f7;
      border: 1px solid #DDD;
      border-top: none;
      border-bottom-left-radius: 4px;
      border-bottom-right-radius: 4px;
      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
      box-sizing: border-box;
      font-family: Open Sans;
      padding: 1rem 1rem;
      margin: 0 0 1.5rem 0;
      user-select: none;
      width: 100%;
    }

    #inputs input {
      height: auto;
    }

    #inputs label {
      margin: 0 0 0 4px;
      cursor: pointer;
      transform: translateY(-2px);
    }

    .row {
      max-width: 600px;
      display: flex;
    }

    .row+.row {
      margin-top: 1rem;
    }

    .col {
      display: flex;
      flex: 1;
    } */
  </style>
</head>

<body class="zc-body">

  <div id="chrome84Overall">
  </div>

  <div id="chrome84Detail">
  </div>

  <div id="inputs">
    <div class="row">

      <div class="col">
        <input type="checkbox" id="checkboxErrors84" checked>
        <label for='checkboxErrors84'>84 Errors</label>
      </div>

      <div class="col">
        <input type="checkbox" id="checkboxIps84" checked>
        <label for="checkboxIps84">84 IP's</label>
      </div>

      <div class="col">
        <input type="checkbox" id="checkboxErrors85">
        <label for="checkboxErrors85">85 Errors</label>
      </div>

      <div class="col">
        <input type="checkbox" id="checkboxIps85">
        <label for="checkboxIps85">85 IP's</label>
      </div>

    </div>
  </div>

  <script>
    ZC.LICENSE = ["xxx", "xxx"]; // DEFINE CHART LOCATIONS (IDS)
    // -----------------------------
    // Main chart render location
    let chrome84Detail = 'chrome84Detail';
    let chrome84Overall = 'chrome84Overall';

    // 定义4各复选框
    // Checkbox Ids
    let checkboxErrors84 = 'checkboxErrors84';
    let checkboxIps84 = 'checkboxIps84';
    let checkboxErrors85 = 'checkboxErrors85';
    let checkboxIps85 = 'checkboxIps85';

    // 包含了浏览器使用数据的数组
    // CHART DATA
    // -----------------------------
    let lastIndex = null;
    let totalUsage = [
      74844938, 67916452, 85397784, 54840784, 71261006, 71914665, 69877920,
      69797876, 64015606, 47538624, 53405488, 71237670, 69854483, 67229795,
      65940984, 59888233, 46967265, 85144680, 63681846, 70527432, 97712043,
      90345661, 67326277, 54836594, 59923602, 78117849, 73954211, 71816590,
      72253684, 64360719, 84948147, 54739648, 69613566, 70720606, 72607842,
      69859811, 64228413, 84706194, 58472683, 68672444, 77388533, 82989307,
      80641084, 79055948, 62823593, 71047012,
    ];
    // 对应的日期数组
    let dates = [
      1598659200000, 1598832000000, 1598918400000, 1599004800000, 1599091200000,
      1599177600000, 1599264000000, 1599350400000, 1599436800000, 1599523200000,
      1599609600000, 1599696000000, 1599782400000, 1599868800000, 1599955200000,
      1600041600000, 1600128000000, 1600214400000, 1600300800000, 1600387200000,
      1600473600000, 1600560000000, 1600646400000, 1600732800000, 1600819200000,
      1600905600000, 1600992000000, 1601078400000, 1601164800000, 1601251200000,
      1601337600000, 1601424000000, 1601510400000, 1601596800000,
    ];

    // 数据
    // Chrome84
    let chrome84 = {
      errors: [
        1987211, 2021396, 1319415, 1323925, 2113920, 2188253, 2170018, 2242853,
        2177930, 1716637, 1705411, 2308796, 2346018, 2260725, 2144784, 1922230,
        1461423, 1536246, 1758595, 2138455, 2180136, 2210526, 1886849, 1319023,
        1496247, 1924003, 1932682, 1657985, 990855, 567546, 428471, 281371, 383746,
        287059, 274365, 271813, 160613, 92252, 122070, 122713, 117868, 147609,
        114567, 78055, 56243, 68693,
      ],
      ips: [
        326981, 188499, 141138, 188086, 188172, 308552, 348591, 164533, 191780,
        202985, 138117, 244959, 290445, 169790, 233407, 179223, 128217, 126069,
        189766, 185304, 392733, 207176, 194674, 116104, 136448, 169075, 156413,
        185558, 69164, 41741, 34424, 19603, 34582, 28694, 25430, 22227, 22204, 9195,
        13378, 14607, 22537, 14738, 18576, 17979, 8901, 6580,
      ],
    };
    chrome84.errorsOverall = chrome84.errors.reduce(combine);
    chrome84.ipsOverall = chrome84.ips.reduce(combine);

    // 数据
    // Chrome85
    let chrome85 = {
      errors: [
        6844, 10334, 78449, 111280, 76589, 89109, 104457, 134231, 166989, 153959,
        209849, 204582, 208316, 313541, 408221, 497291, 995646, 1310197, 1274536,
        1120691, 1579763, 1634092, 1852177, 1865755, 1679352, 1496063, 1575591,
        1994408, 2136103, 1930382, 2231977, 1887391, 1468535, 1543169,
      ],
      ips: [
        1089, 1936, 7473, 15217, 9618, 8606, 16459, 20271, 18850, 25662, 32633,
        15639, 17965, 44984, 53072, 49306, 68848, 112911, 109622, 116628, 270445,
        172383, 230430, 177202, 297868, 153620, 160157, 230393, 269336, 272074,
        137277, 209094, 193838, 259192,
      ],
    };

    // CHART CONFIG
    // -----------------------------

    // Chrome 84
    let chrome84_overall = {
      type: 'area',
      globals: {
        fontFamily: 'Open Sans',
      },
      border: '1px solid #ddd',
      title: {
        text: 'Chrome 84 & 85: Errors vs IPs',
        backgroundColor: 'rgb(247, 247, 247)',
        border: '1px solid #ddd',
        color: 'rgb(44, 84, 55)',
        fontSize: '18px',
        height: '40px',
        padding: '10px',
        textAlign: 'left',
      },
      legend: {
        marginTop: '61px',
        toggleAction: 'none',
      },
      plot: {
        tooltip: {
          visible: false,
        },
        alphaArea: 1,
        marker: {
          visible: false,
        },
      },
      plotarea: {
        margin: '62px 52px 52px',
      },
      scaleY: {
        short: true,
      },
      scaleX: {
        values: dates,
        transform: {
          type: 'date',
          all: '%dd-%M-%y (%D)',
        },
        markers: [{
            type: 'line',
            lineColor: '#2196F3',
            lineWidth: '4px',
            range: [13],
            label: {
              angle: 0,
              backgroundColor: '#2196F3',
              color: '#FFF',
              offsetX: '-58px',
              offsetY: '-285px',
              padding: '5px',
              text: 'Chrome 85 Released',
            },
          },
          {
            alpha: 0.1,
            backgroundColor: '#000',
            type: 'area',
            range: [2, 3],
          },
          {
            alpha: 0.1,
            backgroundColor: '#000',
            type: 'area',
            range: [9, 10],
          },
          {
            alpha: 0.1,
            backgroundColor: '#000',
            type: 'area',
            range: [16, 17],
          },
          {
            alpha: 0.1,
            backgroundColor: '#000',
            type: 'area',
            range: [23, 24],
          },
          {
            alpha: 0.1,
            backgroundColor: '#000',
            type: 'area',
            range: [30, 31],
          },
          {
            alpha: 0.1,
            backgroundColor: '#000',
            type: 'area',
            range: [37, 38],
          },
        ],
      },
      series: [{
          text: 'Errors',
          values: chrome84.errors,      // 指定数据
          backgroundColor: '#3cba54',
          legendItem: {
            text: 'Chrome 84 Errors',
          },
          lineColor: '#3cba54',
          lineWidth: '0px',
        },
        {
          text: 'IPs',
          values: chrome84.ips,      // 指定数据
          backgroundColor: '#f4c20d',
          legendItem: {
            text: 'Chrome 84 IPs',
          },
          lineColor: '#f4c20d',
          lineWidth: '0px',
        },
        {
          text: 'Errors',
          values: chrome85.errors,      // 指定数据
          backgroundColor: '#db3236',
          legendItem: {
            text: 'Chrome 85 Errors',
          },
          lineColor: '#db3236',
          lineWidth: '0px',
          visible: false,
        },
        {
          text: 'IPs',
          values: chrome85.ips,      // 指定数据
          backgroundColor: '#2196F3',
          legendItem: {
            text: 'Chrome 85 IPs',
          },
          lineColor: '#2196F3',
          lineWidth: '0px',
          visible: false,
        },
      ],
      credit: {
        visible: false // 设置此选项为false以隐藏版权信息
      },
      mediaRules: [{
        maxWidth: '700px',
        legend: {
          visible: false,
        },
      }, ],
      crosshairX: {
        plotLabel: {
          backgroundColor: '#FFF',
          border: '1px solid #ddd',
          fontSize: '16px',
          thousandsSeparator: ',',
          padding: '5px',
        },
      },
    };

    // Chrome 84
    let chrome84_detail = {
      type: 'pie',
      globals: {
        fontFamily: 'Open Sans',
      },
      border: '1px solid #ddd',
      title: {
        backgroundColor: 'rgb(247, 247, 247)',
        border: '1px solid #ddd',
        color: 'rgb(44, 84, 55)',
        fontSize: '18px',
        height: '40px',
        padding: '10px',
        text: 'Chrome 84 & 85 Details - Errors vs IPs',
        textAlign: 'left',
      },
      subtitle: {
        text: 'Overall',
        textAlign: 'left',
        x: '6px',
        y: '40px',
      },
      legend: {
        visible: false,
        toggleAction: 'remove',
      },
      plot: {
        tooltip: {
          visible: false,
        },
        valueBox: {
          text: '%t: %v',
          visible: true,
          placement: 'out',
          fontSize: '11px',
          thousandsSeparator: ',',
          offsetR: '15px',
          rules: [{
              rule: '%p == 0',
              placement: 'center',
              offsetY: '-17px',
            },
            {
              rule: '%p == 1',
              placement: 'center',
              offsetY: '-7px',
            },
            {
              rule: '%p == 2',
              placement: 'center',
              offsetY: '7px',
            },
            {
              rule: '%p == 3',
              placement: 'center',
              offsetY: '17px',
            },
          ],
        },
        slice: 70,
      },
      plotarea: {
        margin: '62px 52px 52px',
      },
      series: [{
          text: 'Errors',
          values: [chrome84.errorsOverall],
          backgroundColor: '#3cba54',
        },
        {
          text: 'IPs',
          values: [chrome84.ipsOverall],
          backgroundColor: '#f4c20d',
        },
        {
          text: 'Errors',
          values: [chrome85.errorsOverall],
          backgroundColor: '#db3236',
          visible: false,
        },
        {
          text: 'IPs',
          values: [chrome85.ipsOverall],
          backgroundColor: '#2196F3',
          visible: false,
        },
      ],
      credit: {
        visible: false // 设置此选项为false以隐藏版权信息
      },
    };

    // RENDER CHART
    // -----------------------------

    // AREA
    // Render area chart
    zingchart.render({
      id: chrome84Overall,
      data: {
        gui: {
          behaviors: [{
            id: 'Reload',
            enabled: 'none',
          }, ],
        },
        graphset: [chrome84_overall],
      },
      height: '400px',
      width: '100%',
      events: {
        // lets update the ring chart based on where we are hovering
        guide_mousemove: function(p) {
          // If it's a new index...
          if ((lastIndex && lastIndex !== p.items[0].nodeindex) || !lastIndex) {
            // Update the last index
            lastIndex = p.items[0].nodeindex;
            let detailJSON = zingchart.exec(chrome84Detail, 'getdata');
            for (let i = 0; i < p.items.length; i++) {
              detailJSON.graphset[0].series[p.items[i].plotindex].values = [
                p.items[i].value,
              ];
            }
            detailJSON.graphset[0].subtitle.text = new Date(
              p.items[0].keyvalue
            ).toDateString();
            zingchart.exec(chrome84Detail, 'setdata', {
              data: detailJSON,
            });
          }
        },
        load: loaded(chrome84Overall),
      },
    });

    // RING
    // Render ring chart
    zingchart.render({
      id: chrome84Detail,
      data: {
        gui: {
          behaviors: [{
            id: 'Reload',
            enabled: 'none',
          }, ],
        },
        graphset: [chrome84_detail],
      },
      height: '400px',
      width: '100%',
      events: {
        load: loaded(chrome84Detail),
      },
    });

    // CHECKBOX TOGGLE EVENTS
    // -----------------------------
    document
      .getElementById(checkboxErrors84)
      .addEventListener('click', toggleGraphs);
    document.getElementById(checkboxIps84).addEventListener('click', toggleGraphs);
    document
      .getElementById(checkboxErrors85)
      .addEventListener('click', toggleGraphs);
    document.getElementById(checkboxIps85).addEventListener('click', toggleGraphs);

    // UPDATE THE CHART
    // -----------------------------
    let updateArray = [{
        visible: true
      },
      {
        visible: true
      },
      {
        visible: false
      },
      {
        visible: false
      },
    ];

    // CHART RENDERED
    // -----------------------------
    // Set CSS class to show chart after render
    function loaded(id) {
      let chart = document.querySelector('#' + id);
      chart.classList.add('loaded');
    }

    // HELPER FNS
    // -----------------------------

    // Checkbox click handler
    function toggleGraphs() {
      let plotIndex = 0;

      // Determine plot index
      switch (this.id) {
        case checkboxErrors84:
          plotIndex = 0;
          break;
        case checkboxIps84:
          plotIndex = 1;
          break;
        case checkboxErrors85:
          plotIndex = 2;
          break;
        case checkboxIps85:
          plotIndex = 3;
          break;
      }

      // Toggle array boolean state
      updateArray[plotIndex].visible = this.checked;

      // Update the chart
      zingchart.exec(chrome84Overall, 'appendseriesdata', {
        data: updateArray,
      });
      zingchart.exec(chrome84Detail, 'appendseriesdata', {
        data: updateArray,
      });
    }

    // Combine 2 values
    function combine(a, b) {
      return a + b;
    }
  </script>
</body>

</html>
  • 效果图

标签:false,text,chrome84,ZingChart,错误信息,visible,let,backgroundColor,绘制
From: https://www.cnblogs.com/dogleftover/p/18217155

相关文章

  • Vue+OpenLayers7入门到实战:OpenLayers实现在地图上拖拽编辑修改绘制图形
    返回《Vue+OpenLayers7》专栏目录:Vue+OpenLayers7入门到实战前言本章介绍如何使用OpenLayers7在地图上拖拽编辑修改绘制图形。在前面一章中,我们已经学会了如何绘制基础的三种图形线段、圆形和多边形:《Vue+OpenLayers7入门到实战:OpenLayers图形绘制功能,OpenLayers实现在地......
  • 详解PySide多线程【Python-Pyside图形界面绘制#2】
    在了解pyside多线程之前,如果是初学者可以先去看看我的第一篇文章《超详细实例详解Python多线程》,文中有对多线程的概念进行详细介绍,如果有相关基础可直接跳过。【Python】超详细实例讲解python多线程(threading模块)_pythonthreading介绍-CSDN博客https://blog.csdn.net/Xiao_......
  • iOS开发_绘制圆角矩形虚线环
    -(void)drawRect:(CGRect)rect{//获取上下文(/画笔/绘图环境)CGContextRefcontext=UIGraphicsGetCurrentContext();//小段长度CGFloatline_dash=self.height/20;//虚线的样式:长5空隙15长10空隙30长2空隙20...//CGFloa......
  • Vue3标签组件绘制--自定义按钮组件
    不知道怎么的,突然想绘制一个标签,比如el-button什么的。今天研究一下吧,不知道能不能整出来以后就可以绘制自己的组件,弄自己的组件库了。不知道有朝一日能不能让越组件青史留名?嘻嘻,百日梦做差不多了,接着去查查资料。文章分为三个部分:1.按钮组件实现(根据查阅的一个文章实现基......
  • AutoCAD C# 绘制圆柱
    有这么一个需求我需要将其他软件提取管子信息在AutoCAD中重新搭建3D管线模型数据如下最终AutoCAD模型如下疯转的管子信息代码如下publicclassPipeData{publicstringName{get;set;}publicstringMaterialGrade{get;set;}publicstringCrossSec......
  • 【OpenGL高级】实例化多物体绘制
      一、说明  对于海量而相近物体渲染,如果用buffer直接渲染,其庞大的存储数据将能把整个系统资源耗光。而可行的,用少量模式数据去生成临时显示的数据这样用少量局部变量就能在循环内部完成,本篇将阐述如何去实现。二、实例化渲染  计算机图形学中的实例化是指使用......
  • python绘制多级饼图(分层饼图)
    python绘制多级饼图(分层饼图)介绍效果代码介绍多级饼图展示了数据的层次结构,其中每个级别表示数据的一个层次。我们可以使用matplotlib绘制多级饼图。效果代码importmatplotlib.pyplotasplt#示例数据outer_labels=['CategoryA','CategoryB','Categor......
  • 画布掌航:绘制画布
    绘制画布ヾ(•ω•`)o准备importmatplotlib.pyplotaspltfromIPython.displayimportHTMLimportnumpyasnpfromhtml变量import*......
  • ZingChart绘制金融仪表板
    代码案例<!doctypehtml><html><head><metacharset="utf-8"><title>ZingChartDemo:FinancialWidgetDashboard</title><scriptnonce="undefined"src="./zingchart.min.js"></scr......
  • ZingChart绘制透明样条面积图
    代码案例,参考<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>ZingSoftDemo</title><scriptnonce="undefined"src="https://cdn.zingchart.com/zingchart.min.js"></scrip......