Git Product home page Git Product logo

echarts-auto-tooltip's Introduction

前言

最近, 工作中要做类似这种的项目. 用到了百度的 echarts 这个开源的数据可视化的框架. 安全态势感知

因为投屏项目不像PC端的WEB, 它不允许用户用鼠标键盘等交互. 有些图表只能看到各部分的占比情况, 不能显示具体的数值. 比如:

设计图1 设计图2

得让页面的数据(即tootips)自动轮播数据,效果是这样的.

最终效果图1 最终效果图2

所以 echarts-auto-tooltips 就应运而生.

博客地址

使用方法

  1. 引入ehcrts-auto-tooltips
<script type="text/javascript" src="js/echarts-auto-tooltip.js"></script>
  1. 在初始化 echarts 实例并通过 setOption 方法生成图表的代码下添加如下代码
// 使用指定的配置项和数据显示图表
myChart.setOption(option);
tools.loopShowTooltip(myChart, option, {loopSeries: true}); // 使用本插件

参数说明:

mychart: 初始化echarts的实例

option: 指定图表的配置项和数据

loopOption: 本插件的配置

属性 说明 默认值
interval 轮播时间间隔,单位毫秒 默认为2000
loopSeries true表示循环所有series的tooltip,false则显示指定seriesIndex的tooltip boolean类型,默认为false
seriesIndex 指定某个系列(option中的series索引)循环显示tooltip,当loopSeries为true时,从seriesIndex系列开始执行. 默认为0

实例代码

function drawSensitiveFile() {
            let myChart = echarts.init(document.getElementById('sensitive-file'));
            let option = {
                title: {
                    text: '敏感文件分布分析',
                    x: '40',
                    textStyle: {
                        color: '#fff'
                    }

                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)",

                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    right: 10,
                    top: 20,
                    bottom: 20,
                    data: ['人事类', '研发类', '营销类', '客户信息类'],
                    textStyle: {
                        color: '#fff'
                    }
                },
                series: [
                    {
                        name: '敏感文件分布数量',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: [
                            {value: 335, name: '人事类'},
                            {value: 310, name: '研发类'},
                            {value: 234, name: '营销类'},
                            {value: 1548, name: '客户信息类'}
                        ],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        labelLine: {
                            normal: {
                                //length:5,  // 改变标示线的长度
                                lineStyle: {
                                    color: "#fff"  // 改变标示线的颜色
                                }
                            },
                        },
                        label: {
                            normal: {
                                textStyle: {
                                    color: '#fff'  // 改变标示文字的颜色
                                }
                            }
                        },
                    }
                ]
            };

            myChart.setOption(option);

			tools.loopShowTooltip(myChart, option, {loopSeries: true});

        }

echarts-auto-tooltip's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.