如何下划线和粗体工具提示图表js

时间:2017-10-10 16:06:06

标签: javascript angular chart.js

我的网站上有一个图表问题: 我想在工具提示上加一些粗体和下划线的文字,就像这张图片一样。

ChartJs图片: enter image description here

我发现可以采取: tooltipTitleFontStyle:"粗体" titleFontStyle:'粗体' 但都没有效果。

你有解决方案吗?

1 个答案:

答案 0 :(得分:0)

您好,您可以构建自己的工具提示,以便它可以在任何地方返回,即自定义html

http://www.chartjs.org/docs/latest/configuration/tooltip.html#external-custom-tooltips

对于粗体字体,titleFontStyle的选项必须位于options.tooltips:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [
        {
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
        },  
            {
                label: '# of Points',
                data: [7, 11, 5, 8, 3, 7],
                borderWidth: 1
            }
        ]
  },
  options: {
    scales: {
        yAxes: [{
        ticks: {
                    reverse: false
        }
      }]
    },
    tooltips: {
        titleFontStyle: 'bold',
      titleFontSize: 24
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);

你可以在这里看到一个有效的例子:

https://jsfiddle.net/fpjzvh4m/

希望这有帮助。

P.D:我建议在询问这类问题时,你要包含一些代码。

相关问题