简体   繁体   English

Google Charts DataView Tooltip HTML呈现为字符串

[英]Google Charts DataView Tooltip HTML rendering as string

# I know rows parse correctly as the chart does render
@data = new google.visualization.arrayToDataTable rows
if @get('tooltipCol') isnt false
  (columns or []).forEach (col, index)=>
    if index is 0
      return
    # This sets every other column as a tooltip
    if not (index % 2)
      @data.setColumnProperties( index, {
        type: 'string'
        role: 'tooltip'
        'p': { 'html': true }
      })

# This starts another function where @data is the actual table data from above
view = new google.visualization.DataView(@data)

# data here is the model options which includes data.tooltip.isHtml: true
@chart.draw view, data

My chart data is parsed fine. 我的图表数据已解析良好。 It even seems to recognize that I want the tooltip to be html as the rendering is slightly different. 甚至似乎认识到我希望工具提示为html,因为呈现方式略有不同。

But it basically just renders the html as text instead of parsed html. 但是它基本上只是将html呈现为文本,而不是解析的html。

There are quite a few questions on SO asking the same question but none seem to deal with the DataView. 因此,有很多问题都在问同样的问题,但似乎没有一个与DataView有关。 Here is one : Google Charts - full html in tooltips 这是一个: Google图表-工具提示中的完整html

I'm using the DataView as I use a custom legend to hide and show columns. 我使用DataView时是使用自定义图例来隐藏和显示列。 (the whole process of tooltips in Google charts makes this very convoluted) Anyway, everything works except for the parsing of html. (Google图表中工具提示的整个过程非常复杂)无论如何,除html的解析外,其他所有方法都有效。

Any suggestions. 有什么建议么。 BTW, the above code is just snippets. 顺便说一句,上面的代码只是片段。 Hopefully you can follow along, if not I can post some more. 希望您能继续下去,如果没有,我可以再发表一些。

In response to tmdean 回应tmdean

I tried, view.toDataTable() and could not get the html to parse with that, which surprised me. 我尝试了view.toDataTable(),但无法获取html进行解析,这让我感到惊讶。 So I then use @chart.draw @data, data to use the original DataTable. 所以我然后使用@chart.draw @data, data使用原始DataTable的数据。 This did not work either so I thought perhaps I was doing something wrong. 这也不起作用,所以我以为我做错了什么。

I ran data.getColumnProperties(2) (data here is an exported variable to the console which references @data in the code) Which should be my first tooltip and this is what I got: 我运行了data.getColumnProperties(2) (这里的数据是控制台中导出的变量,该变量在代码中引用了@data)应该是我的第一个工具提示,这就是我得到的: 在此处输入图片说明

It appears to see that. 看来看到了。

I also made sure I was passing in data.tooltip.isHtml:true and I am 我还确保我正在传递data.tooltip.isHtml:true,我是

在此处输入图片说明

I'm at a loss at the moment. 我现在不知所措。 Seems like this should be an easy thing to do. 看起来这应该是一件容易的事。 Do I need to encode my html or anything? 我需要对html或其他内容进行编码吗?

This is a poorly documented feature (setting existing column to tooltip), but have found an answer. 这是一个文档很少的功能(将现有列设置为工具提示),但是找到了答案。 The p : {html: true} is actually an abbreviature of properties:{html: true} . p : {html: true}实际上是properties:{html: true}的缩写。 So my guess was: Why use a method called setColumnProperties and put as a parameter properties ? 所以我的猜测是:为什么使用名为setColumnProperties的方法并将其作为参数properties Well, tried to remove that and it worked: 好吧,尝试删除它,它起作用了:

data.setColumnProperties( 2, {
   role: 'tooltip',
   html: true 
})  

Have you tried converting your DataView to a DataTable prior to rendering it? 在渲染数据视图之前,您是否尝试过将其转换为数据表? Just call toDataTable() on the DataView. 只需在DataView上调用toDataTable()。

Google Visualization has a lot of quirks when rendering DataViews. 呈现DataView时,Google Visualization有很多怪癖。 It's usually best to just convert to a DataTable even though there's a (usually actually pretty small) performance penalty. 即使存在性能损失(通常实际上很小),通常最好也只是转换为DataTable。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM