我正在尝试通过将自定义 html 工具提示添加到数据表中来在我的 google 图表中创建自定义 html 工具提示,现在我的数据表正在 PHP 中创建,如下所示:
$datatable = array('cols' => array(
array('type' => 'string', 'role' => 'domain', 'label' => 'Month'),
array('type' => 'string', 'role' => 'tooltip'),
array('type' => 'string', 'role' => 'domain', 'label' => 'Omzet'),
array('type' => 'number', 'label' => 'Omzet '.$jaar),
array('type' => 'number', 'label' => 'Omzet '.($jaar-1)),
array('type' => 'string', 'role' => 'domain', 'label' => 'Aantal'),
array('type' => 'number', 'label' => 'Aantal '.$jaar),
array('type' => 'number', 'label' => 'Aantal '.($jaar-1))
));
并像这样填充:
$datatable['rows'][] = array('c' => array(
array('v' => $monthname),
array('v' => '<h1>custom</h1> tooltip '.$monthname),
array('v' => 'Omzet '.$monthname),
array('v' => $row['totaal']),
array('v' => $omzet),
array('v' => 'Aantal'),
array('v' => $row['aantal']),
array('v' => $aantal)
));
但是对于您可以在 Javascript 中为 google 图表指定的数据表,您必须添加类似的内容
dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});
否则工具提示将以纯文本形式显示,而不是 html 标记https://developers.google.com/chart/interactive/docs/customizing_tooltip_content#customizing-html-content https://developers.google.com/chart/interactive/docs/customizing_tooltip_content#customizing-html-content
这意味着我必须以某种方式添加'p': { 'html': true }我的数据表的属性
我尝试将其编辑为
array('type' => 'string', 'role' => 'tooltip', 'p' => '{ html : true}'),
甚至到
array('type' => 'string', 'role' => 'tooltip', 'html' => true),
但这些似乎都不起作用,我也无法在谷歌上找到方法。
我希望我已经提供了足够的信息来帮助找到答案,如果您需要更多信息,请告诉我。
这是我第一次在这里发布问题,所以请友善(: