简体   繁体   English

chart.js颜色不呈现

[英]chart.js color not rendering

I am trying to use chart.js to create a simple live line/scatter chart, z-indexed to act as a backdrop for my app. 我正在尝试使用chart.js创建一个简单的实时线/散点图,z-indexed作为我的应用程序的背景。 For some reason, it's rendering as an opaque gray color instead of the reddish color I've specified. 出于某种原因,它呈现为不透明的灰色而不是我指定的偏红色。 And, even though I've tried changing the other chart elements and defaults the chart is always gray. 而且,即使我尝试更改其他图表元素和默认值,图表也始终是灰色的。 I'm sure it's a trivial fix but just i can not figure it out. 我确定这是一个微不足道的修复,但我无法理解。

Here is the link to a JS Bin that has the full code.(You'll need to set and start the timer before the chart will have any data to show) Also, more specifically, this is the JS code related to creating the chart: 以下是具有完整代码的JS Bin的链接。(您需要在图表显示任何数据之前设置并启动计时器)此外,更具体地说,这是与创建图表相关的JS代码:

var ctx = document.getElementById('canvas').getContext("2d"),
points = [{x:0,y:0}],
lineData = {
    datasets: [{
        fillColor: "rgba(217, 108, 99, .9)",
        strokeColor: "rgba(255, 255, 255, 1)",
        pumpntHighlightStroke: "rgba(220,220,220,1)",
        data: points
    }]
},
lineOptions = {
    showScale: false,
    scaleShowLabels: false,
    scaleShowGridLines : false,
    pointDot : false,
    pointDotRadius : 0,
    pointDotStrokeWidth : 0,
    pointHitDetectionRadius : 0,
    datasetStroke : true,
    datasetStrokeWidth : 3,
    datasetFill : true,
};
Chart.defaults.global.elements.point.radius = 0;
Chart.defaults.global.legend.display = false;
Chart.defaults.global.tooltips.enabled = false;
Chart.defaults.global.animation.duration = 250;
Chart.scaleService.updateScaleDefaults('linear', {
    display: false,
    ticks: {
        beginAtZero: true,
        min: 0
    }
});
Chart.defaults.global.elements.line.tension = 0.05;
Chart.defaults.global.maintainAspectRatio = false;

myChart = new Chart(ctx, {
    type: 'scatter',
    data: lineData,
    options: lineOptions
});

Thank you for your time. 感谢您的时间。 please let me know if there is anything further I can explain. 如果还有什么可以解释的,请告诉我。

I think this is because you don't use the correct properties. 我认为这是因为你没有使用正确的属性。 According to the docs ( http://www.chartjs.org/docs/ ), you should use backgroundColor , not fillColor . 根据文档( http://www.chartjs.org/docs/ ),您应该使用backgroundColor ,而不是fillColor

See the first example in the doc: http://www.chartjs.org/docs/#getting-started-creating-a-chart 请参阅doc中的第一个示例: http//www.chartjs.org/docs/#getting-started-creating-a-chart

     datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: [
            'rgba(255, 99, 132, 0.2)',
            'rgba(54, 162, 235, 0.2)',
            'rgba(255, 206, 86, 0.2)',
            'rgba(75, 192, 192, 0.2)',
            'rgba(153, 102, 255, 0.2)',
            'rgba(255, 159, 64, 0.2)'
        ],
        borderColor: [
            'rgba(255,99,132,1)',
            'rgba(54, 162, 235, 1)',
            'rgba(255, 206, 86, 1)',
            'rgba(75, 192, 192, 1)',
            'rgba(153, 102, 255, 1)',
            'rgba(255, 159, 64, 1)'
        ],
        borderWidth: 1
    }]

Note that strokeColor doesn't exist aswell. 请注意, strokeColor也不存在。

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

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