Search code examples
chart.jsfont-familyreact-chartjs-2

how to change default font family in react-chartjs-2


i have bar chart with "react-chartjs-2", where should i put my font family for labels of chart in xAxes: this way:(not worked)

<Bar
    data={chartData}
    options={{ defaults: { global: { defaultFontFamily:"iransans} }}}
/>

this way not worked to:

    <Bar
        data={chartData}
        options={{ font: { family: "iransans" }}}
    />

any body know this????


Solution

  • so after seeing a post in github, this way worked: first import defaults:

    import { defaults } from 'react-chartjs-2';
    

    and then somewhere set font like this:

    defaults.font.family = 'font name...';