热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在谷歌图表中悬停的垂直线-Verticallinesonhoveringooglecharts

Iamworkingwithgooglelinechartsandangularjsdirectiveinmyproject,Iamsearchinghowtoge

I am working with google line charts and angularjs directive in my project, I am searching how to get vertical lines on hover like Google Trends instead put a fixed lines, but I can't find how to do this.

在我的项目中,我正在使用谷歌线图和angularjs指令,我正在寻找如何使垂线像谷歌趋势一样悬停,而不是放置固定的线,但是我找不到如何做到这一点。

This is that I want trying to do:

这就是我想做的:

enter image description here

I just got hide vertical lines but not show on mouse hover, this is my options for angular-google-chart directive

我只是隐藏了垂直的线但没有显示在鼠标悬停上,这是我对angular-google-chart指令的选择

options: {
  vAxis: {
    title: 'My title',
    gridlines: {
      count: 10
    }
  },
  hAxis: {
    title: 'title hAxis',
    gridlines: {
      color: 'transparent'
    }
  }
}

2 个解决方案

#1


2  

there are no standard config options for this, but you could add your own line on hover...

这里没有标准的配置选项,但是您可以在hover上添加您自己的行……

see following working snippet for an example...

请参见下面的工作代码片段以获得一个示例……

google.charts.load('current', {
  callback: drawChart,
  packages: ['corechart']
});

function drawChart() {
  var dataTable = new google.visualization.DataTable({
    cols: [
      {id: 'x', label: 'Date', type: 'date'},
      {id: 'y', label: 'Fn', type: 'number'}
    ]
  });

  var formatDate = new google.visualization.DateFormat({
    pattern: 'MMM d, yyyy'
  });

  var OneDay= (1000 * 60 * 60 * 24);
  var startDate = new Date(2016, 1, 21);
  var endDate = new Date();
  var ticksAxisH = [];
  for (var i = startDate.getTime(); i 

#2


0  

Thanks to @WhiteHat in his previous answer, I have adjusted his code to use it with angular-google-charts in an angular 1.5 component, this is my approach:

感谢@WhiteHat在他之前的回答中,我调整了他的代码,将它与角-谷歌-海图放在一个角- 1.5组件中,这就是我的方法:

Angular-google-charts have some directives to attach custom events like mouseover, mouseout, ready etc, Example:

Angular-google-charts有一些附加自定义事件的指令,比如mouseover、mouseout、ready等,例如:

 
如果您能看到,我已经添加了agc-on-ready, agc-on-mouseover和agc-on-mouseout这些指令允许我将我的定制函数附加到这些事件上。

Using @WhiteHat solutions my functions are here:

使用@WhiteHat解决方案,我的功能如下:

self.OnMouseOver= function (row, column) {
    if (row !== null) {
        var dataTable=self.chartWrapper.getDataTable();
        var xPos = self.layout.getXLocation(dataTable.getValue(row, 0));
        self.svgParent.appendChild(self.hoverLine);
        self.hoverLine.setAttribute('x', xPos);

        // This line is neccesary to move the line under the tooltip     
        self.svgParent.insertBefore(self.hoverLine, self.svgParent.children[4]);
    }
}

self.OnMouseOut= function (row, column) {
    if (row !== null) {
        self.svgParent.removeChild(self.hoverLine);
    }
}

self.OnReady= function (chartWrapper) {
    // Define vars for draw vertical line on hoverLine  
    self.chartWrapper = chartWrapper;

    // Getting container from chartWrapper.getContainerId()
    var cOntainer= angular.element(chartWrapper.getContainerId());
    self.svgParent = container[0].getElementsByTagName('svg')[0];
    self.layout = chartWrapper.getChart().getChartLayoutInterface();
    self.lineHeight = self.layout.getBoundingBox('chartarea').height - 18;
    self.lineTop = self.layout.getBoundingBox('chartarea').top;

    self.hoverLine = container[0].getElementsByTagName('rect')[0].cloneNode(true);
    self.hoverLine.setAttribute('y', self.lineTop);
    self.hoverLine.setAttribute('z', 100);
    self.hoverLine.setAttribute('height', self.lineHeight);
    self.hoverLine.setAttribute('width', '1');
    self.hoverLine.setAttribute('stroke', 'none');
    self.hoverLine.setAttribute('stroke-width', '0');
    self.hoverLine.setAttribute('fill', '#cccccc');

};

I hope you find it useful and your comments to improve this implementation.

我希望您能发现它的有用性和您的评论来改进这个实现。


推荐阅读
  • 本文总结了在编写JS代码时,不同浏览器间的兼容性差异,并提供了相应的解决方法。其中包括阻止默认事件的代码示例和猎取兄弟节点的函数。这些方法可以帮助开发者在不同浏览器上实现一致的功能。 ... [详细]
  • HTML5网页模板怎么加百度统计?
    本文介绍了如何在HTML5网页模板中加入百度统计,并对模板文件、css样式表、js插件库等内容进行了说明。同时还解答了关于HTML5网页模板的使用方法、表单提交、域名和空间的问题,并介绍了如何使用Visual Studio 2010创建HTML5模板。此外,还提到了使用Jquery编写美好的HTML5前端框架模板的方法,以及制作企业HTML5网站模板和支持HTML5的CMS。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了css回到顶部按钮相关的知识,希望对你有一定的参考价值。 ... [详细]
  • higuysihaveproblemwithtreeshakinginnx,problemwithassetslibrary ... [详细]
  • 可视化神经网络的网络结构并保存
    可视化神经网络的网络结构并保存#导入基础包和方法#LoadlibrariesfromkerasimportmodelsfromkerasimportlayersfromIP ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Html5-Canvas实现简易的抽奖转盘效果
    本文介绍了如何使用Html5和Canvas标签来实现简易的抽奖转盘效果,同时使用了jQueryRotate.js旋转插件。文章中给出了主要的html和css代码,并展示了实现的基本效果。 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • 本文记录了作者对x265开源代码的实现与框架进行学习与探索的过程,包括x265的下载地址与参考资料,以及在Win7 32 bit PC、VS2010平台上的安装与配置步骤。 ... [详细]
  • 本文介绍了Java后台Jsonp处理方法及其应用场景。首先解释了Jsonp是一个非官方的协议,它允许在服务器端通过Script tags返回至客户端,并通过javascript callback的形式实现跨域访问。然后介绍了JSON系统开发方法,它是一种面向数据结构的分析和设计方法,以活动为中心,将一连串的活动顺序组合成一个完整的工作进程。接着给出了一个客户端示例代码,使用了jQuery的ajax方法请求一个Jsonp数据。 ... [详细]
  • 工作经验谈之-让百度地图API调用数据库内容 及详解
    这段时间,所在项目中要用到的一个模块,就是让数据库中的内容在百度地图上展现出来,如经纬度。主要实现以下几点功能:1.读取数据库中的经纬度值在百度上标注出来。2.点击标注弹出对应信息。3 ... [详细]
  • #include<iostream>usingnamespacestd;intmain(){HereIseperatemynumberbe ... [详细]
  • 我正在尝试将Firebase添加到涉及添加以下内容的现有应用程序中:classpath'com.googl ... [详细]
  • 时域|波形_语音处理基于matlab GUI音频数据处理含Matlab源码 1734期
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了语音处理基于matlabGUI音频数据处理含Matlab源码1734期相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 今天周六,原则上要休息,但想到下周还有一堆任务,还是先做一部分工作吧,就把之前做的票面设计器改了改,增加了上传图片和更换背景底图的功能。现在打算整理下这个设计器,也算对齐一个总结。不过这属于我们部门的 ... [详细]
author-avatar
手机用户2502858457
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有