简体   繁体   English

使Chart.js ToolTip不同于数据

[英]Make Chart.js ToolTip different then data

I am new to front-end development and I am curious what is the best way to have the tooltip in Chart 2.0 and Angular-Charts Beta 1.0 different from the label being passed back?: 我是前端开发的新手,并且很好奇,使Chart 2.0和Angular-Charts Beta 1.0中的工具提示与传递回的标签不同的最佳方法是什么:

HTML: HTML:

<canvas id="panel1bar" class="chart-bar" height="229px"
                chart-series="[profile['detail']['freq-histogram'].series]"
                chart-labels="profile['detail']['freq-histogram']['short-labels']"
                chart-data="[profile['detail']['freq-histogram'].data]"
                chart-colours="['#008080']"
                chart-legend="false"/>

If only there was an option to set chart-tooltip = "profile['detail']['freq-histogram']['long-labels']" 如果只有一个选项可以设置chart-tooltip =“ profile ['detail'] ['freq-histogram'] ['long-labels']”

I only ask this as I am getting a long and short label passed back to me and I want to display the full label on Hover in the tool tip 我只问这个问题,因为我收到的是长短标签,我想在工具提示的“悬停”上显示完整标签

There should be a chart-options attribute for the canvas. 画布应该有一个chart-options属性。 You can add it like: chart-options="chartOptions" . 您可以像这样添加它: chart-options="chartOptions"

Then on your controller you can change the tooltip template by using this code: 然后在您的控制器上,您可以使用以下代码来更改工具提示模板:

$scope.chartOptions = {
     tooltipTemplate: "<%= value %>"
}

But i am not sure if it works properly in chartjs 2.0. 但是我不确定它是否可以在chartjs 2.0中正常工作。 For that you can check this issue here : https://github.com/chartjs/Chart.js/issues/2322 为此,您可以在这里检查此问题: https : //github.com/chartjs/Chart.js/issues/2322

You could pass this to the attribute chart-options="options" : 您可以将其传递给属性chart-options="options"

$scope.options= {
    tooltips: {
        callbacks: {
            title: function(tooltipItem, data) {
                return $scope.profile['detail']['freq-histogram']['long-labels'][tooltipItem[0].index];
            }
        }
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM