tooltip is not shown as expected when customized

后端 未结 1 1641
刺人心
刺人心 2021-01-24 08:38

I am working on angularjs google charts. I want to customize the tooltip. In my tooltip i want to show the multiple series data as well as some text as shown in the demo https:/

1条回答
  •  清酒与你
    2021-01-24 08:59

    if you use a continuous axis ('number', 'date', 'timeofday', etc...) for the first column,

    you can provide the tooltip value as the formatted value (f:)

    {"c":[{"v": 0, "f":"Jan - July"},{"v":63},{"v":"30"},{"v":"33"}]},
    

    then use hAxis.ticks for the axis labels
    use the same object notation to set the label value

    hAxis: {
      ticks: [
        {"v": 0, "f":"First Series"},
        {"v": 1, "f":"Second Series"},
        {"v": 2, "f":"Third Series"}
      ]
    },
    

    other options are included in the following snippet,
    to format the chart similar to using a discrete axis ('string')

    google.load('visualization', '1.1', {
      packages: ['corechart'],
      callback: drawChart
    });
    
    function drawChart() {
      var data = new google.visualization.DataTable({
        "cols": [
          {"id": 'title', "label": 'title', "type": "number"},
          {"id": "count", "label": "count", "type": "number"},
          {"id": "pizza", "label": "Pizza", "type": "number"},
          {"id": "softdrink", "label": "Softdrink", "type": "number"}
        ],
        "rows": [
          {"c":[{"v": 0, "f":"Jan - July"},{"v":63},{"v":"30"},{"v":"33"}]},
          {"c":[{"v": 1, "f":"Aug - Sept"},{"v":70},{"v":"35"},{"v":"35"}]},
          {"c":[{"v": 2, "f":"Oct - Dec"},{"v":80},{"v":"40"},{"v":"40"}]}
        ]
      });
    
      options = {
        title: 'title',
        isStacked: true,
        focusTarget: 'category',
        hAxis: {
          baselineColor: 'transparent',
          gridlines: {
            color: 'transparent'
          },
          slantedText: false,
          ticks: [
            {"v": 0, "f":"First Series"},
            {"v": 1, "f":"Second Series"},
            {"v": 2, "f":"Third Series"}
          ]
        },
        tooltip: {
          text: 'value'
        }
      }
    
      var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
    
    

    UPDATE

    placing the above changes in angular...

    var createChart = function (rows, label) {
          return {
              "type": "ColumnChart",
              "data": {
                  "cols": [
                      {"id": label, "label": label, "type": "number"},
                      {"id": "count", "label": "count", "type": "number"},
                      {"id": "pizza", "label": "Pizza", "type": "number"},
                      {"id": "softdrink", "label": "Softdrink", "type": "number"}
                  ],
                  "rows": rows
              },
              "options": {
                title: 'title',
                isStacked: true,
                focusTarget: 'category',
                hAxis: {
                  baselineColor: 'transparent',
                  gridlines: {
                    color: 'transparent'
                  },
                  slantedText: false,
                  ticks: [
                    {"v": 0, "f":"First Series"},
                    {"v": 1, "f":"Second Series"},
                    {"v": 2, "f":"Third Series"}
                  ]
                },
                tooltip: {
                  text: 'value'
                }
              }
          }
      };
    
    var data = [
        {"c":[{"v": 0, "f":"Jan - July"},{"v":63},{"v":"30"},{"v":"33"}]},
        {"c":[{"v": 1, "f":"Aug - Sept"},{"v":70},{"v":"35"},{"v":"35"}]},
        {"c":[{"v": 2, "f":"Oct - Dec"},{"v":80},{"v":"40"},{"v":"40"}]}
      ];
    

    0 讨论(0)
提交回复
热议问题