我正在使用PHP/mongodb/javascript构建我的谷歌图表折线图。在php中,我制作了一列作为角色工具提示(最后一列)。现在我看到的默认工具提示是X轴(日期)和Y轴(值)。但我想在工具提示中显示日期、值和其他信息(图像版本)。对于工具提示列,它应该覆盖默认的工具提示,但它没有发生。
如果我在选项中添加focusTarget:类别,我可以看到日期、值和图像版本,但对于整个类别,我不希望这样。我只想看到我点击或悬停的那个点的日期、值和图像版本。
从谷歌文档FocusTarget来看:"数据"似乎是我想要的。当我这样做时,我再次只看到默认的工具提示。
基本上,默认工具提示被自定义工具提示覆盖的唯一一次是当我使用focustarget:category时。
不确定我错过了什么。
$table = array();
$table['cols'] = array(
array('label' => 'Date','type' => 'date')
);
array_push($table['cols'], array('type' => 'string', 'role' => "tooltip"));
array_push($table['cols'], array('label' => 'Label', 'type' => 'string'));
$numCols = count($table['cols']) - 1;
$numColsMinus1 = count($table['cols']) - 2;
从数据库,值进入阵列
$rows[$row_index]['c'][$numColsMinus1]['v'] = $r["image_ver"];
$rows[$row_index]['c'][$col_index]['v'] = $r[$datatype];
$rows[$row_index]['c'][$numCols]['v'] = $label;
下面是谷歌图表包装
var chart = new google.visualization.ChartWrapper({
'chartType': 'LineChart',
'containerId': 'chart_div',
'options': {
'interpolateNulls': 'true',
'curveType': 'false',
'animation':{
'duration': 1000,
'easing': 'inAndOut'
},
'titleTextStyle':{ 'fontName': "Verdana", 'fontSize': 15, 'bold': 'false', 'italic': 'false' },
'tooltip': {
'textStyle': { 'fontName': "Arial", 'fontSize': 14, 'italic': 'false' },
//'isHtml': 'true'
//'trigger' : 'selection',
//'trigger' : 'both',
//'trigger' : 'focus'
//'legend' : 'none'
},
"focusTarget": "category",
//"focusTarget": "datum",
//"focusTarget": "",
//"focusTarget": "series",
'chartArea': {'height': '85%', 'width': '70%'},
'hAxis': {'slantedText': false, 'maxAlternation': 1, 'viewWindowMode': 'pretty'},
'allowHtml': 'true',
'legend': {'allowHtml': 'true',
'textStyle': {fontSize: 11}},
'pointSize': 3
}
});
大多数角色列都应用于最左边的邻居数据列,如Google图表文档中所示。如果您希望为"折线图"中的所有线条提供自定义工具提示,则必须为每条线条添加一个角色列。我认为你不需要为focusTarget而烦恼。