首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ChartJS悬停工具提示颜色不显示其正确的颜色

问ChartJS悬停工具提示颜色不显示其正确的颜色
EN

Stack Overflow用户
提问于 2020-04-30 14:12:30
回答 1查看 581关注 0票数 0

我用ChartJS制作了这个图表。到目前为止,我已经让它工作了,但是,当添加更多的数据时,比如2行..工具提示将丢失其颜色。我说的是值左边的白框:

​

​

正如你所看到的,这里有两行。一个是收入,一个是存款。存款是最低的,收益是最高的。为什么白色正方形是白色的?应该和这条线一样吗?

下面是我的代码:

图表:

代码语言:javascript
复制
var ctx = document.getElementById('orders_graph').getContext('2d');

    var Order_chart = new Chart(ctx, {
        // The type of chart we want to create
        type: 'line',

        // The data for our dataset
        data: {
            labels: [], // months
            datasets: [{
                label: 'Fortjenelse',
                data: []
            }]
        },

        // Configuration options go here
        options: 
        {
            responsive: true,
            hover: {
              mode: 'index',
              intersect: false
            },
            spanGaps: true,

            legend: {
                display: false
            },
            tooltips: {
                mode: 'index',
                intersect: false,
                callbacks: {
                   label: function(tooltipItem) {
                          return ' '+tooltipItem.yLabel+' DKK';
                       }
                   }
            },
            layout: { 
                // padding: { left: 0, right: 0, top: 10, bottom: 30}
            },
            scales:{
                xAxes: [{
                    display: true //this will remove all the x-axis grid lines
                }],
                yAxes: [{
                    display: true, //this will remove all the x-axis grid lines
                    stacked: false,
                    ticks: {
                        beginAtZero: true
                    },
                }],
            }
        }
    });

将数据传递给图表:

代码语言:javascript
复制
Order_chart.data.labels = order_array_parent_index;
        Order_chart.data.datasets = [{
                                        // Fortjenelse med renter
                                        label: 'Profit',
                                        data: order_array_parent,
                                        fill: false,
                                        lineTension: 0,
                                        backgroundColor: [
                                            'rgba(113, 217, 98, 0.2)',
                                        ],
                                        borderColor: [
                                            'rgba(113, 217, 98, 1)',
                                        ],

                                    },
                                    {
                                        // Deposited amount
                                        label: 'Deposit',
                                        data: order_array_parent_deposits,
                                        fill: false,
                                        lineTension: 0,
                                        backgroundColor: [
                                            'rgba(255, 223, 82, 0.2)',
                                        ],
                                        borderColor: [
                                            'rgba(255, 223, 82, 1)',
                                        ],

                                    },
                                    ]
        Order_chart.update(); 

对如何解决这个问题有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-30 14:31:39

浏览一下Chart.js文档,工具提示bgColor似乎不在一个数组中,而只是一个颜色参数。试着把backgroundColor: [ the color ]改成backgroundColor: 'rgba(x,x,x,x)'我没有Chart.js,所以我不能测试,但我想这会让你感觉不错。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61516968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档