首页 > 解决方案 > 如何为画布标签赋予样式?

问题描述

我有一个用 javascript 和 canvas 标签制作的图表。但我不能给图表提供css。我想要做的是改变轴的 dataPoints 的颜色(X 和 Y 轴的数据编号)

这是我的javascript代码;

                     <script>
                        var xValues = {{past_data1|safe}} ;
                        var yValues={{past_data2|safe}}
                        new Chart("myChart-bottom", {
                        type: "line",
                        data: {
                          labels: xValues,
                          datasets: [{
                            data: yValues,
                            labelFontColor: "green",
                            borderColor: "red",
                            fill: false,
                          }]
                        },
                        options: {
                          legend: {display: false}
                        }
                      });
                    </script>

这也是我的画布标签的html代码;

<canvas id="myChart-bottom" style="width: 90%; max-width:600px; margin-top: 10px;
                            border-style: solid; border-color: grey; padding-top: 20px; padding-right: 20px; border-radius: 10px;
                            background-color: dark-grey"></canvas>

'labelFontColor: "green"' 部分实际上不起作用。那么我该怎么做才能给线条上的 dataPoints 赋予颜色呢?

标签: javascripthtmlcsscanvas

解决方案


推荐阅读