nvd3工具提示显示索引而不是标签

时间:2017-02-07 06:32:14

标签: javascript angularjs d3.js nvd3.js

我在multichart(multilinechart)中遇到问题nvd3工具提示。我的XAxis标签是JAN,FEB,MAR... DEC.,但是当我在图表中鼠标悬停时,它会显示0,1,2,3.. 11作为工具提示标题。但我需要显示JAN,FEB.. DEC而不是索引。这是我的图表选项代码,

{
  "chart": {
    "type": "multiChart",
    "height": 400,
    "interpolate": "linear",
    "showLegend": false,
    "margin": {
      "top": 50,
      "right": 100,
      "bottom": 60,
      "left": 100
    },
    "reduceXTicks": false,
    "useVoronoi": false,
    "useInteractiveGuideline": true,
    "duration": 500,
    "xAxis": {
      "axisLabel": "MONTHLY",
      "tickPadding": 10,
      "tickSize": 1,
      "tickValues": [
        0,
        1,
        2,
        3,
        4,
        5,
        6
      ]
    },
    "yAxis1": {
      "axisLabel": "Left",
      "tickPadding": 10
    },
    "yAxis2": {
      "axisLabel": "Right",
      "width": 60,
      "tickPadding": 10
    },
    "yDomain1": [
      0,
      5
    ],
    "yDomain2": [
      0,
      100
    ]
  }
}

这是图像中的问题(需要显示FEB,但它显示1), enter image description here 这是第二个(需要显示MAR,但它显示2) enter image description here

请帮助确定问题,

先谢谢。

1 个答案:

答案 0 :(得分:1)

您可以尝试使用方法interactiveLayer.tooltip.headerFormatter来修改标题的标签,例如:

chart.interactiveLayer.tooltip.headerFormatter(d => {
      if (typeof d === 'string') return d
    })