在 php 数据表中添加属性以用于 google 图表自定义 html 工具提示

2024-01-11

我正在尝试通过将自定义 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),

但这些似乎都不起作用,我也无法在谷歌上找到方法。

我希望我已经提供了足够的信息来帮助找到答案,如果您需要更多信息,请告诉我。

这是我第一次在这里发布问题,所以请友善(:


你走在正确的轨道上array('type' => 'string', 'role' => 'tooltip', 'p' => '{ html : true}'),但你需要一个额外的数组'html': true part.

它应该看起来像array('type' => 'string', 'role' => 'tooltip', 'p' => array('html' => true));

我在这里尝试了一下:链接到测试 http://sandbox.onlinephpfunctions.com/code/497caa96ae7ce2fc82af8bb0449b50a7c9c52954

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 php 数据表中添加属性以用于 google 图表自定义 html 工具提示 的相关文章