如何在图表的传说中增加字体大小。

发布于 2025-02-10 11:39:59 字数 3038 浏览 1 评论 0原文

我正在尝试在我使用Chart.js的图中增加标签的字体大小。 附带有屏幕截图: 我想增加“标签1,2,3”的字体尺寸。

在我现在正在使用的JavaScript配置下方:

var data = {
    labels: x_axis_labels,
    datasets: [
        {
            label: 'Label 1',
            data: data_1,
            borderColor: 'rgb(46,138,207)',
            backgroundColor: 'rgb(46,138,207)',
            yAxisID: 'y',
        },
        {
            label: 'Label 2',
            data: data_2,
            borderColor: 'rgb(214,224,52)',
            backgroundColor: 'rgb(214,224,52)',
            yAxisID: 'y1',
        },
        {
            data: data_3,
            label:'Label 3',
            borderColor: 'rgb(244,67,54)',
            backgroundColor: 'rgb(244,67,54)',
            yAxisID: 'y1',
            pointStyle:'dash',
            borderDash: [20, 30],
            pointBackgroundColor: "transparent",
        },
    ]
};

const config = {
    type: 'line',
    data: data,
    options: {
        
        responsive: true,
        interaction: {
            mode: 'index',
            intersect: false,
        },
        stacked: false,
        plugins: {

            title: {
                display: true,
              
            }
        },
        scales: {

            x:{
                title:{
                    display: true,
                    text: 'X axis name',
                    font: {size:30},
                },
                ticks: {
                    font: {
                        size: 20,
                    }
                }
            },
            y: {
                title:{
                    display: true,
                    text: 'First y axis name',
                    font: {size:30}
                },
                type: 'linear',
                display: true,
                position: 'left',
                ticks: {
                    font: {
                        size: 24,
                    }
                }
            },
            y1: {
                title:{

                    display: true,
                    text: 'Second Y axis name',
                    font: {size:30}
                },
                type: 'linear',
                display: true,
                position: 'right',
                ticks:{
                    font:{
                        size:24,
                    }
                },
                // grid line settings
                grid: {
                    drawOnChartArea: false, 
                },
            },
        },
    },
};

我尝试了 font documnation and logend documentation 但是我什么都没有。 有人有经验吗? 提前致谢

I am trying to increase labels' font size in the legend of a plot that I have done with chart.js.
Attached there is a screenshot:
enter image description here
I want to increase the font size of "Label 1,2,3".

Below the javascript configuration that I am using right now:

var data = {
    labels: x_axis_labels,
    datasets: [
        {
            label: 'Label 1',
            data: data_1,
            borderColor: 'rgb(46,138,207)',
            backgroundColor: 'rgb(46,138,207)',
            yAxisID: 'y',
        },
        {
            label: 'Label 2',
            data: data_2,
            borderColor: 'rgb(214,224,52)',
            backgroundColor: 'rgb(214,224,52)',
            yAxisID: 'y1',
        },
        {
            data: data_3,
            label:'Label 3',
            borderColor: 'rgb(244,67,54)',
            backgroundColor: 'rgb(244,67,54)',
            yAxisID: 'y1',
            pointStyle:'dash',
            borderDash: [20, 30],
            pointBackgroundColor: "transparent",
        },
    ]
};

const config = {
    type: 'line',
    data: data,
    options: {
        
        responsive: true,
        interaction: {
            mode: 'index',
            intersect: false,
        },
        stacked: false,
        plugins: {

            title: {
                display: true,
              
            }
        },
        scales: {

            x:{
                title:{
                    display: true,
                    text: 'X axis name',
                    font: {size:30},
                },
                ticks: {
                    font: {
                        size: 20,
                    }
                }
            },
            y: {
                title:{
                    display: true,
                    text: 'First y axis name',
                    font: {size:30}
                },
                type: 'linear',
                display: true,
                position: 'left',
                ticks: {
                    font: {
                        size: 24,
                    }
                }
            },
            y1: {
                title:{

                    display: true,
                    text: 'Second Y axis name',
                    font: {size:30}
                },
                type: 'linear',
                display: true,
                position: 'right',
                ticks:{
                    font:{
                        size:24,
                    }
                },
                // grid line settings
                grid: {
                    drawOnChartArea: false, 
                },
            },
        },
    },
};

I have tried Font Documnetation and Legend Documentation but I got nothing.
Someone had experience in this?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-02-17 11:39:59

如文档中所述

options: {
  plugins: {
    legend: {
      labels: {
        font: {
          size: 20
        }
      }
    }
  }
}

As described in the docs you can set the size in the options.plugins.legend.labels.font.size namespace

options: {
  plugins: {
    legend: {
      labels: {
        font: {
          size: 20
        }
      }
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文