可视化图表与页面源代码显示

可视化图表与页面源代码显示

页面效果:
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
  <meta charset="utf-8">
  <title>饼状图</title>
  <style>
    body {
      display: flex;
      height: 100%;
      margin: 0;
    }
    #container {
      flex: 1;
      height: 100%;
    }
    #source-container {
      flex: 1;
      overflow: auto;
      padding: 20px;
      background-color: rgba(111, 231, 35, 0.36); /* 背景色以便区分 */
    }
    #downloadButton {
      padding: 10px 20px;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      font-size: 16px;
      position: absolute;
      top: 20px;
      right: 20px;
      z-index: 1000;
    }
    #downloadButton:hover {
      background-color: #0056b3;
    }
  </style>
</head>
<body>
  <div id="container"></div>
  <div id="source-container">
    <pre id="source-code"></pre>
  </div>
  <button id="downloadButton" onclick="downloadSource()">下载</button>

  <script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/echarts.min.js"></script>
  <script type="text/javascript">
    var dom = document.getElementById('container');
    var myChart = echarts.init(dom, null, {
      renderer: 'canvas',
      useDirtyRect: false
    });
    var app = {};

    var option;

    setTimeout(function () {
  option = {
    legend: {},
    tooltip: {
      trigger: 'axis',
      showContent: false
    },
    dataset: {
      source: [
        ['年份', '2012', '2013', '2014', '2015', '2016', '2017'],
        ['数据1', 56.5, 82.1, 88.7, 70.1, 53.4, 85.1],
        ['数据2', 51.1, 51.4, 55.1, 53.3, 73.8, 68.7],
        ['数据3', 40.1, 62.2, 69.5, 36.4, 45.2, 32.5],
        ['数据4', 25.2, 37.1, 41.2, 18, 33.9, 49.1]
      ]
    },
    xAxis: { type: 'category' },
    yAxis: { gridIndex: 0 },
    grid: { top: '55%' },
    series: [
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' }
      },
      {
        type: 'pie',
        id: 'pie',
        radius: '30%',
        center: ['50%', '25%'],
        emphasis: {
          focus: 'self'
        },
        label: {
          formatter: '{b}: {@2012} ({d}%)'
        },
        encode: {
          itemName: '年份',
          value: '2012',
          tooltip: '2012'
        }
      }
    ]
  };
  myChart.on('updateAxisPointer', function (event) {
    const xAxisInfo = event.axesInfo[0];
    if (xAxisInfo) {
      const dimension = xAxisInfo.value + 1;
      myChart.setOption({
        series: {
          id: 'pie',
          label: {
            formatter: '{b}: {@[' + dimension + ']} ({d}%)'
          },
          encode: {
            value: dimension,
            tooltip: dimension
          }
        }
      });
    }
  });
  myChart.setOption(option);
});

    if (option && typeof option === 'object') {
      myChart.setOption(option);
    }

    // 将源代码放入右侧的容器中
    document.getElementById('source-code').textContent = document.documentElement.outerHTML;

    // 按钮函数
    function downloadSource() {
      const source = document.documentElement.outerHTML;
      const blob = new Blob([source], { type: 'text/html' });
      const url = window.URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = 'chart-source.html';
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
      window.URL.revokeObjectURL(url);
    }

    window.addEventListener('resize', myChart.resize);
  </script>
</body>
</html>

万能代码:将下面这段代码放入任何一个前端(html,css,js)可视化图表示例中,在其页面上都会显示源码及页面下载这个按钮功能

<!--在html中写入-->
<div id="source-container">
    <pre id="source-code"></pre>
  </div>
  <button id="downloadButton" onclick="downloadSource()">下载</button>
/*在CSS中写入*/
body {
      display: flex;
      height: 100%;
      margin: 0;
    }
    #container {
      flex: 1;
      height: 100%;
    }
    #source-container {
      flex: 1;
      overflow: auto;
      padding: 20px;
      background-color: rgba(111, 231, 35, 0.36); /* 背景色以便区分 */
    }
    #downloadButton {
      padding: 10px 20px;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      font-size: 16px;
      position: absolute;
      top: 20px;
      right: 20px;
      z-index: 1000;
    }
    #downloadButton:hover {
      background-color: #0056b3;
    }
//在js中写入
 // 将源代码放入右侧的容器中
    document.getElementById('source-code').textContent = document.documentElement.outerHTML;

    // 下载按钮
    function downloadSource() {
      const source = document.documentElement.outerHTML;
      const blob = new Blob([source], { type: 'text/html' });
      const url = window.URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = 'chart-source.html';
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
      window.URL.revokeObjectURL(url);
    }
  • 17
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
基于电商平台618的Python可视化分析设计与实现源代码主要包括以下内容: 1. 数据获取:利用Python编写爬虫程序,通过接口或网页爬取电商平台618期间的商品销售数据,包括商品名称、价格、销量、评价等信息,并保存为CSV或Excel文件。 2. 数据预处理:对获取到的原始数据进行清洗和处理,包括去除重复数据、处理缺失值、转换数据类型等操作,以确保数据的准确性和完整性。 3. 可视化设计:利用Python的数据可视化库(如Matplotlib、Seaborn、Plotly等),根据需求设计合适的图表形式,如柱状图、折线图、饼图等,展示618期间商品的销售情况、价格变动趋势、评价分布等信息。 4. 可视化实现:根据设计的图表形式,编写Python代码,使用相应的可视化库进行绘图,并设置合适的图表标题、坐标轴标签、图例等内容,以增加图表的可读性和信息传达效果。 5. 交互功能添加:根据需要,可以添加交互式功能,例如鼠标悬停显示细节信息、图表类型选择切换等,以增强用户体验。 6. 结果呈现:将生成的可视化图表保存为图片或网页的形式,以便在电商平台618分析报告中使用或在线展示。 总结起来,基于电商平台618的Python可视化分析设计与实现源代码主要包括数据获取、数据预处理、可视化设计、可视化实现、交互功能添加和结果呈现等步骤。通过这些步骤的实施,可以将618期间的电商数据以直观、清晰、易于理解的图表形式展示出来,为业务决策和数据分析提供有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

温轻舟

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值