ngx-charts热图使用tooltipTemplate自定义工具提示

时间:2017-08-30 04:50:03

标签: angular tooltip heatmap ngx-charts

我尝试使用此代码自定义ngx-charts-heat-map的工具提示

<ng-template #tooltipTemplate let-item="item">
  <h1>
    {{getFlag(item.name)}}
  </h1>
  <h2>{{item.name}}: {{item.value}}</h2>
</ng-template>

如果数据是单个对象数组,而不是多对象数据

,我意识到这项工作就好了
export var single = [
  {
    "name": "Germany",
    "value": 8940000
  },
  {
    "name": "USA",
    "value": 5000000
  },
  {
    "name": "France",
    "value": 7200000
  }
];

export var multi = [
  {
    "name": "Germany",
    "series": [
      {
        "name": "2010",
        "value": 7300000
      },
      {
        "name": "2011",
        "value": 8940000
      }
    ]
  },

  {
    "name": "USA",
    "series": [
      {
        "name": "2010",
        "value": 7870000
      },
      {
        "name": "2011",
        "value": 8270000
      }
    ]
  },

  {
    "name": "France",
    "series": [
      {
        "name": "2010",
        "value": 5000002
      },
      {
        "name": "2011",
        "value": 5800000
      }
    ]
  }
];

ngx-charts-heat-map只允许多个对象,有没有办法自定义工具提示?也许还有传说

1 个答案:

答案 0 :(得分:0)

<ngx-charts-bar-vertical-2d>(或类似图表)元素中使用以下形式的模板:

<ng-template #tooltipTemplate let-model="model">
    <!-- fields are series/name/value -->
    <div class="tt">
      {{ model.series }}
      | {{ model.name }}
      | {{ model.value }}
    </div>
</ng-template>

基于当前文档派生的示例的StackBlitz示例: https://stackblitz.com/edit/vertical-bar-chart-kfjrxe