dongmin3754 2015-06-08 12:33
浏览 26
已采纳

在php数据表中为google chart自定义html工具提示添加属性

I am trying to create custom html tooltips in my google chart by adding them into the datatable, right now my datatable is being created in PHP like this:

  $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))
));

and filled like this:

$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)
));

however for the datatable you can specify in Javascript for the google chart, you have to add something like

dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});

otherwise the tooltip would come out as plain text instead of html markup https://developers.google.com/chart/interactive/docs/customizing_tooltip_content#customizing-html-content

which means I will have to somehow add the 'p' : { 'html' : true } property to my datatable

I have tried by editing it to

array('type' => 'string', 'role' => 'tooltip', 'p' => '{ html : true}'),

or even to

array('type' => 'string', 'role' => 'tooltip', 'html' => true),

but none of these seem to work and I can't find a way to do it on google either.

I hope i've given enough information to help come up with an answer, if there's anything more you need please let me know.

This is my first time posting a question here so please be nice (:

  • 写回答

3条回答 默认 最新

  • doucitao2944 2015-06-15 10:40
    关注

    You were on the right track with array('type' => 'string', 'role' => 'tooltip', 'p' => '{ html : true}'),but you need to have an additional array for the 'html': true part.

    It should look like array('type' => 'string', 'role' => 'tooltip', 'p' => array('html' => true));

    I tried it out here: Link to test

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥40 图书信息管理系统程序编写
  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题