Change tool-tip direction in react-chartjs2

回眸只為那壹抹淺笑 提交于 2019-12-11 18:42:30

问题


I have implemented the react-chartjs2 https://www.npmjs.com/package/react-chartjs-2 in my react app. I have implemented it successfully but i need to change the direction of the tooltip when hovering the chart. Currently it looks like this

But i want my tooltip to look like this

How can i achieve this

My code for chart and chart options

const barChartOptions = {
  tooltips: {
    custom: function(tooltip) {
      if (!tooltip) return;
      // disable displaying the color box;
      tooltip.displayColors = false;
    },
    callbacks: {
      // use label callback to return the desired label
      label: function(tooltipItem, data) {
        return tooltipItem.yLabel + " kWh";
      },
      // remove title
      title: function(tooltipItem, data) {
        return;
      }
    }
  },
  responsive: true,
  maintainAspectRatio: false,
  legend: {
    display: false
  },
  scales: {
    xAxes: [
      {
        barPercentage: 1,
        barThickness: 10,
        gridLines: {
          display: false,
          color: "rgba(0, 0, 0, 0.1)"
        }
      }
    ],
    yAxes: [
      {
        gridLines: {
          display: true,
          categorySpacing: 90,
          drawBorder: false,
          color: "rgba(0, 0, 0, 0.1)"
        },
        ticks: {
          beginAtZero: true,
          min: 0,
          max: 100,
          stepSize: 20,
          padding: 20
        }
      }
    ]
  }
};

inside render

<Bar
  data={data}
  width={100}
  height={400}
  options={barChartOptions}
/>

回答1:


I think you need to add more configuration for your tooltip

Check what you can use for position and alignment of your Tooltip

Hope this will help you.Let me know if you have any problem.




回答2:


options: {
    tooltips: {
      yAlign: "bottom"
    }
}

The problem is I don't know a way that the caret is in the middle of your box.



来源:https://stackoverflow.com/questions/58709699/change-tool-tip-direction-in-react-chartjs2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!