2

我尝试使用此代码自定义 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 只允许多对象,有没有办法自定义工具提示?也可能是传说

4

1 回答 1

4

<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

于 2019-02-16T02:15:36.373 回答