简体   繁体   English

Chart.js 数据点的颜色变化

[英]Chart.js color change of the data points

I want to make the dots solid color instead of a border of the line color.我想让点变成纯色而不是线条颜色的边框。 How do I remove the border color from the data points and make it a solid color?如何从数据点中删除边框颜色并使其成为纯色?

Current Output:当前Output:

在此处输入图像描述

What I want:我想要的是: 在此处输入图像描述

You can set point and point border to same color.您可以将点边框设置为相同的颜色。

datasets: [
    {
      label: 'Dataset 1',
      data: Utils.numbers(NUMBER_CFG),
      fill: false,
      borderColor: Utils.CHART_COLORS.red,
      backgroundColor: '#1F363D', # Here
      borderWidth: 1,
      pointRadius: 5,
      pointBorderColor: '#1F363D' #Here
    },

在此处输入图像描述

You can set the color value for each data point an array.您可以为数组中的每个数据点设置颜色值。

data: {
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
            ],
            borderWidth: 1
        }]

在此处输入图像描述

codepen - https://codepen.io/non_tech_guy/pen/VwzwRrL codepen - https://codepen.io/non_tech_guy/pen/VwzwRrL

The only catch I can see is the first borderColor value controls the color of the line but it is a step closer.我能看到的唯一问题是第一个 borderColor 值控制线条的颜色,但它更近了一步。

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

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