简体   繁体   English

Google Charts API:始终使用arrayToDataTable显示数据点值。 怎么样?

[英]Google Charts API: Always show the Data Point Values using arrayToDataTable. How?

First I'd like to let it be known that although there is a similar question labeled: 首先,我想让大家知道,尽管有一个类似的问题标记为:

Google Charts API: Always show the Data Point Values in Graph Google Charts API:始终在图形中显示数据点值

...on the site, I can't seem to use it's solution since my chart is fed using arrayToDataTable . ...在网站上,由于图表是使用arrayToDataTable填充的 ,因此我似乎无法使用它的解决方案。

Here's my code: 这是我的代码:

  function drawChart1998() {
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Index Trend'],
      ['1/3', 1236777],
      ['1/7', 834427],
      ['1/10', 2164890],
      ['1/14', 1893574],
      ['1/17', 2851881],
      ['1/21', 359504],
      ['1/24', 2264047],
      ['1/28', 3857933],
      ['1/31', 2197402],
      ['2/4', 2469935],
      ['2/7', 1651752],
      ['2/11', 4710582],
      ['2/14', 1565803],
      ['2/18', 345499],
      ['2/21', 2817319],
      ['2/25', 733242],
      ['2/28', 1485788],
      ['3/4', 1091181],
      ['3/7', 4477498],
      ['3/11', 490931],
      ['3/14', 3905556],
      ['3/18', 475417],
      ['3/21', 1512729],
      ['3/25', 1782796],
      ['3/28', 4778434]

    ]);

    var options = {
      curveType: "function",
      title: '1998 Results',
      vAxis: {viewWindow: {min: 0, max: 5006386}},
      hAxis: {textStyle: {color: 'black', fontName: 'verdana', fontSize: 10} },
      series: {0: { pointSize: 6 }}
    };

    var chart = new google.visualization.LineChart(document.getElementById('chart_1998'));
    chart.draw(data, options);

  }

As you can see, I managed to set the series to display the DataPoint dots but I can't seem to figure out how to incorporate the following line of code as the previous post on the site suggests in order to display the values for each DataPoint. 如您所见,我设法将系列设置为显示DataPoint点,但似乎无法弄清楚如何合并下面的代码行,如该站点上的上一篇文章所建议的那样,以便显示每个DataPoint的值。

data.addColumn({type: 'string', role: 'annotation'});

For reference, you can input an annotation column to your DataTable using the arrayToDataTable method. 作为参考,您可以使用arrayToDataTable方法将注释列输入到DataTable中。 Pass an object instead of a string for the column header: 为列标题传递一个对象而不是一个字符串:

var data = google.visualization.arrayToDataTable([
    [/* column headers */, {type: 'string', role: 'annotation'}, /* column headers */],
    // ...
]);

This works for any column role. 这适用于任何列角色。

If you just want to display the value of a data point, you don't have to add an extra column to your DataTable. 如果只想显示数据点的值,则不必在DataTable中添加额外的列。 You can use a DataView to add an "annotation" column, calculated as the string-value of a source column: 您可以使用DataView添加“注释”列,该列的计算方式为源列的字符串值:

var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
    type: 'string',
    role: 'annotation',
    sourceColumn: 1,
    calc: 'stringify'
}]);

Then draw the chart using the view instead of the DataTable: 然后使用视图而不是DataTable绘制图表:

chart.draw(view, options);

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

相关问题 Google Charts API:在折线图中显示数据点值 - Google Charts API: Show Data Point Values in Line Chart Google Charts,定义变量和 arrayToDataTable - Google Charts, define variables and arrayToDataTable Google Charts - PHP 数组到 JS 的问题(arrayToDataTable 的数据不是数组) - Google Charts - issue with PHP Array to JS (Data for arrayToDataTable is not an array) 如何使用 Google charts API 柱状图绘制单个数据点? - How to plot a single data point with Google charts API column chart? 来自ajax的google-charts javascript arrayToDataTable - google-charts javascript arrayToDataTable from ajax 如何在“Google Chart”arrayToDataTable上添加html标签中的数据? 使用javascript - How to add the data from html tag on “Google Chart” arrayToDataTable? using javascript Google Charts, AJAX, PHP 问题编码 JSON 错误:arrayToDataTable 的数据不是数组 - Google Charts, AJAX, PHP Problem Encoding JSON Error: Data for arrayToDataTable is not an array 如何将 HTML 数据(标签)作为值包含在 Google 饼图的“arrayToDataTable”中? - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart? 如何在Google图表中使用arraytodatatable使用类别过滤器 - How to use category filter using arraytodatatable in google chart 构建php数组以传递给Google饼图arrayToDataTable - Structuring php array to pass to google pie charts arrayToDataTable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM