2012-12-28 93 views
3

我在尝试更改来自Google API的气泡图中气泡的工具提示。自定义Google Charts API中的气泡图工具提示

角色:可以解决我的问题的tooltip不适用于这种图表。

现在我的气泡显示有关行的值的信息,根据文档,这是正确的,但我只需要该信息绘制图表,我需要显示一个字符串作为工具提示。这个字符串是由我需要格式化的一些值组成的。

可以这样做吗?

对于记录,我使用PHP通过JSON向Javascript提供数据,我使用的是谷歌最新的API(https://www.google.com/jsapi)。

这是我列的定义,因为他们现在是正确的:

$data['cols'][] = array('id' => 'ID', 'label' => 'ID', 'pattern' => "", 'type' => 'string'); 
$data['cols'][] = array('id' => 'Fecha', 'label' => 'Fecha', 'pattern' => "", 'type' => 'number'); 
$data['cols'][] = array('id' => 'h', 'label' => 'h', 'pattern' => "", 'type' => 'number'); 
$data['cols'][] = array('id' => 'stringRes', 'label' => 'Valor', 'pattern' => "", 'type' => 'string'); 
$data['cols'][] = array('id' => 'Resultado', 'label' => 'Resultado', 'pattern' => "", 'type' => 'number'); 

提前感谢!

编辑:

[解决方法]

如果有人问同样的问题,我刚好擦除我不想显示的字段的标签解决我的问题,就是这样!

我改变了我的列模型如下:

$data['cols'][] = array('id' => 'ID', 'label' => 'Fecha', 'pattern' => "", 'type' => 'string'); 
$data['cols'][] = array('id' => 'Fecha', 'label' => '', 'pattern' => "", 'type' => 'number'); 
$data['cols'][] = array('id' => 'h', 'label' => '', 'pattern' => "", 'type' => 'number'); 
$data['cols'][] = array('id' => 'stringRes', 'label' => 'Resultado', 'pattern' => "", 'type' => 'string'); 
$data['cols'][] = array('id' => 'Resultado', 'label' => '', 'pattern' => "", 'type' => 'number'); 

感谢@jmac给了我的问题的一些方法。

+0

如果您可以将解决方案添加到下面的答案中,然后将自己的答案检查为“已解决”,那么将有助于将问题显示为已解决,并让他人在未来需要时查看问题/答案。 – jmac

回答

0

[解决方法]

如果有人问同样的问题,我解决我的问题仅通过擦除我不想显示的字段的标签,那就是它!

我改变了我的列模型如下:

$data['cols'][] = array('id' => 'ID', 'label' => 'Fecha', 'pattern' => "", 'type' => 'string'); 
$data['cols'][] = array('id' => 'Fecha', 'label' => '', 'pattern' => "", 'type' => 'number'); 
$data['cols'][] = array('id' => 'h', 'label' => '', 'pattern' => "", 'type' => 'number'); 
$data['cols'][] = array('id' => 'stringRes', 'label' => 'Resultado', 'pattern' => "", 'type' => 'string'); 
$data['cols'][] = array('id' => 'Resultado', 'label' => '', 'pattern' => "", 'type' => 'number'); 

感谢@jmac给了我的问题的一些方法。

1

对于您的数据,您可以使用setFormattedValue()来绘制图表,并在鼠标悬停时弹出一个不同的数字。因为要导入的数据,我们无法看到的格式,没有太多我们可以做确切地告诉你如何处理它,但这里有一个例子:

var drawVisualizations = function() { 
    // Create and populate a data table. 
    var data = new google.visualization.DataTable(); 
    data.addColumn('string', 'Force'); 
    data.addColumn('number', 'Level'); 

    // Add 2 rows. 
    // google.visualization.DataTable.addRows() can take a 2-dim array of values. 
    data.addRows([['Fire', 1], ['Water', 5]]); 

    // Add one more row. 
    data.addRow(['sand', 4]); 

    // Draw a table with this data table. 
    var originalVisualization = new google.visualization.Table(document.getElementById('original_data_table')); 
    originalVisualization.draw(data); 

    // Clone the data table and modify it a little. 
    var modifiedData = data.clone(); 

    // Modify existing cell. 
    modifiedData.setFormattedValue(1, 1, "one"); 

    // Draw a table with this data table. 
    var modifiedVisualization = new google.visualization.Table(document.getElementById('modified_data_table')); 
    modifiedVisualization.draw(modifiedData); 
} 

在你的情况,你会需要创建一个循环访问数据表的功能,并根据需要设置其格式,但无论如何,这将使您能够将数字绘图作为一件事物,但显示为另一种。