Charts 谷歌可视化API-条形图/折线图-自定义工具提示

Charts 谷歌可视化API-条形图/折线图-自定义工具提示,charts,tooltip,visualization,gwt-visualization,Charts,Tooltip,Visualization,Gwt Visualization,如何格式化基于Google Visualization Api的线条图和条形图的工具提示文本 我想在工具提示中自定义文本和图像。 谢谢这里似乎有一些关于如何做到这一点的细节 向下滚动到底部,这是最后一个示例。只需将此代码放入Google的可视化操场,作为示例,我正在使用条形图并编辑工具提示的文本: function drawVisualization() { data = new google.visualization.DataTable() data.addColumn('

如何格式化基于Google Visualization Api的线条图和条形图的工具提示文本

我想在工具提示中自定义文本和图像。
谢谢

这里似乎有一些关于如何做到这一点的细节


向下滚动到底部,这是最后一个示例。

只需将此代码放入Google的可视化操场,作为示例,我正在使用条形图并编辑工具提示的文本:

function drawVisualization() {
    data = new google.visualization.DataTable()
    data.addColumn('string', 'Date');
    data.addColumn('number');
    data.addColumn({type:'string',role:'tooltip'});
    data.addRow();
    base = 10;
    data.setValue(0, 0, 'Datapoint1');
    data.setValue(0, 1, base++);
    data.setValue(0, 2, " This is my tooltip1 ");

    data.addRow();
    data.setValue(1, 0, 'Datapoint2');
    data.setValue(1, 1, base++);
    data.setValue(1, 2, "This is my second tooltip2");

    // Draw the chart.
    var chart = new google.visualization.BarChart(document.getElementById('visualization'));
    chart.draw(data, {legend:'none', width:600, height:400});
}
将此粘贴到:

函数drawVisualization(){
//准备数据
var data=new google.visualization.DataTable();
data.addColumn('string','Name');
data.addColumn('number','Donuts eated');
addColumn({'type':'string','role':'tooltip','p':{'html':true}});
data.addRows([
['Sven',16,createCustomHTMLContent('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRnV6emFCNN90Nt-HQcd_x5umqdospagup5fwqc5qynvpehhf8',16)],
['Kurt',46,createCustomHTMLContent('http://173.199.167.192/customavatars/avatar296423_1.gif', 46)],
['Sofie',27,createCustomHTMLContent('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSbv9ijKCwG3eJS9uUTxPzJ5F8zqYRAA5uRkyfz5lniC7TN8t96', 27)],
['Lisa',29,createCustomHTMLContent('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQLZSgX1oDVc5psdBdqzG8oU-1vqTEIMXw-FDvoSLOg0oJ-0VLv',29],
['Lajla',19,createCustomHTMLContent('http://static3.depositphotos.com/1001992/155/i/950/depositphotos_1550168-Portrait-of-a-beauty-young-female-face.jpg', 19)],
['Elsa',38,createCustomHTMLContent('http://os1.i.ua/3/2/10725917_2535e604.jpg', 38)],    
]);
函数createCustomHTMLContent(flagURL、TotalURL){
返回“”+
“
”+ '' + '' + '' + ''+TotalEated+''+ '' + '' + ''; } //为“吃甜甜圈”列定义滑块控件 var slider=new google.visualization.ControlWrapper({ “controlType”:“NumberArrangeFilter”, “containerId”:“control1”, “选项”:{ 'filterColumnLabel':'Donuts Earted', 'ui':{'labelStacking':'vertical'} } }); //定义饼图 var piechart=new google.visualization.ChartWrapper({ “chartType”:“ColumnChart”, “集装箱运输”:“图表1”, “选项”:{ “宽度”:600, ‘高度’:300, “图例”:“底部”, “工具提示”:{ “isHtml”:对 }, “文本”:“值” } }); //创建仪表板。 新的google.visualization.Dashboard(document.getElementById('Dashboard'))。 //配置滑块以影响图表 绑定(滑块、图表)。 //绘制仪表板 绘制(数据); }
这里有一些工具提示示例

下面是柱状图的示例:

    function drawChart() {
      var dataTable = new google.visualization.DataTable();
      dataTable.addColumn('string', 'Country');
      // Use custom HTML content for the domain tooltip.
      dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});
      dataTable.addColumn('number', 'Gold');
      dataTable.addColumn('number', 'Silver');
      dataTable.addColumn('number', 'Bronze');

      dataTable.addRows([
        ['USA', createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg', 46, 29, 29), 46, 29, 29],
        ['China', createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/f/fa/Flag_of_the_People%27s_Republic_of_China.svg', 38, 27, 23), 38, 27, 23],
        ['UK', createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/a/ae/Flag_of_the_United_Kingdom.svg', 29, 17, 19), 29, 17, 19]
      ]);

      var options = {
        title: 'London Olympics Medals',
        colors: ['#FFD700', '#C0C0C0', '#8C7853'],
        // This line makes the entire category's tooltip active.
        focusTarget: 'category',
        // Use an HTML tooltip.
        tooltip: { isHtml: true }
      };

      // Create and draw the visualization.
      new google.visualization.ColumnChart(document.getElementById('custom_html_content_div')).draw(dataTable, options);
    }

    function createCustomHTMLContent(flagURL, totalGold, totalSilver, totalBronze) {
      return '<div style="padding:5px 5px 5px 5px;">' +
          '<img src="' + flagURL + '" style="width:75px;height:50px"><br/>' +
          '<table id="medals_layout">' + '<tr>' +
          '<td><img         src="http://upload.wikimedia.org/wikipedia/commons/1/15/Gold_medal.svg" style="width:25px;height:25px"/></td>' +
  '<td><b>' + totalGold + '</b></td>' + '</tr>' + '<tr>' +
  '<td><img src="http://upload.wikimedia.org/wikipedia/commons/0/03/Silver_medal.svg" style="width:25px;height:25px"/></td>' +
  '<td><b>' + totalSilver + '</b></td>' + '</tr>' + '<tr>' +
  '<td><img src="http://upload.wikimedia.org/wikipedia/commons/5/52/Bronze_medal.svg" style="width:25px;height:25px"/></td>' +
  '<td><b>' + totalBronze + '</b></td>' + '</tr>' + '</table>' + '</div>';
    }e
函数绘图图(){
var dataTable=new google.visualization.dataTable();
addColumn('string','Country');
//为域工具提示使用自定义HTML内容。
addColumn({'type':'string','role':'tooltip','p':{'html':true});
dataTable.addColumn('number','Gold');
dataTable.addColumn('number','Silver');
dataTable.addColumn('number','brown');
dataTable.addRows([
['USA',createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg', 46, 29, 29), 46, 29, 29],
[“中国”,createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/f/fa/Flag_of_the_People%27s_Republic_of_China.svg', 38, 27, 23), 38, 27, 23],
['UK',createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/a/ae/Flag_of_the_United_Kingdom.svg', 29, 17, 19), 29, 17, 19]
]);
变量选项={
标题:“伦敦奥运会奖牌”,
颜色:['#FFD700'、'#C0C0'、'#8C7853'],
//此行将激活整个类别的工具提示。
焦点目标:“类别”,
//使用HTML工具提示。
工具提示:{isHtml:true}
};
//创建并绘制可视化。
新的google.visualization.ColumnChart(document.getElementById('custom_html_content_div')).draw(dataTable,options);
}
函数createCustomHTMLContent(flagURL、totalGold、totalSilver、totalBronze){
返回“”+
“
”+ '' + '' + '' + ''+totalGold+''++ '' + ''+totalSilver+''++ '' + ''+TotalBrown+''+''+''+''+''; }e
Thanx这非常有用。但这对我在这方面没有帮助。请注意,答案应该是搜索解决方案的终点(与另一个中途停留的引用相比,它往往会随着时间的推移而过时)。请考虑在这里添加一个独立的概要,将链接作为参考。
    function drawChart() {
      var dataTable = new google.visualization.DataTable();
      dataTable.addColumn('string', 'Country');
      // Use custom HTML content for the domain tooltip.
      dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});
      dataTable.addColumn('number', 'Gold');
      dataTable.addColumn('number', 'Silver');
      dataTable.addColumn('number', 'Bronze');

      dataTable.addRows([
        ['USA', createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/2/28/Flag_of_the_USA.svg', 46, 29, 29), 46, 29, 29],
        ['China', createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/f/fa/Flag_of_the_People%27s_Republic_of_China.svg', 38, 27, 23), 38, 27, 23],
        ['UK', createCustomHTMLContent('http://upload.wikimedia.org/wikipedia/commons/a/ae/Flag_of_the_United_Kingdom.svg', 29, 17, 19), 29, 17, 19]
      ]);

      var options = {
        title: 'London Olympics Medals',
        colors: ['#FFD700', '#C0C0C0', '#8C7853'],
        // This line makes the entire category's tooltip active.
        focusTarget: 'category',
        // Use an HTML tooltip.
        tooltip: { isHtml: true }
      };

      // Create and draw the visualization.
      new google.visualization.ColumnChart(document.getElementById('custom_html_content_div')).draw(dataTable, options);
    }

    function createCustomHTMLContent(flagURL, totalGold, totalSilver, totalBronze) {
      return '<div style="padding:5px 5px 5px 5px;">' +
          '<img src="' + flagURL + '" style="width:75px;height:50px"><br/>' +
          '<table id="medals_layout">' + '<tr>' +
          '<td><img         src="http://upload.wikimedia.org/wikipedia/commons/1/15/Gold_medal.svg" style="width:25px;height:25px"/></td>' +
  '<td><b>' + totalGold + '</b></td>' + '</tr>' + '<tr>' +
  '<td><img src="http://upload.wikimedia.org/wikipedia/commons/0/03/Silver_medal.svg" style="width:25px;height:25px"/></td>' +
  '<td><b>' + totalSilver + '</b></td>' + '</tr>' + '<tr>' +
  '<td><img src="http://upload.wikimedia.org/wikipedia/commons/5/52/Bronze_medal.svg" style="width:25px;height:25px"/></td>' +
  '<td><b>' + totalBronze + '</b></td>' + '</tr>' + '</table>' + '</div>';
    }e