热门标签 | 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.

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


推荐阅读
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社区 版权所有