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.
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:
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.