Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Line chart] X and Y axis and tooltip fonts are being set only after hovering the chart #337

Closed
bagratinho opened this issue Sep 7, 2018 · 2 comments
Labels
Awaiting Reproduction Bug needs to be reproduced. bug
Projects

Comments

@bagratinho
Copy link

I'm trying to set a Google Font on the canvas, its embed in the separate css file. What happens is that the charts takes the default browser font at the initial rendering, and right font appears only after hovering on any chart point for tooltip to appear and then moving the mouse out of the chart.

See example: https://codesandbox.io/s/xpqvy2ojkw

import React from "react";
import ReactDOM from "react-dom";
import { Line } from "react-chartjs-2";

import "./styles.css";

function App() {
  return (
    <Line
      options={{
        tooltips: {
          displayColors: false,
          backgroundColor: "black",
          enabled: true,
          mode: "single",
          bodyFontSize: 15,
          bodyFontFamily: "Gamja Flower",
          bodyFontColor: "white",
          yPadding: 5,
          xPadding: 15,
          cornerRadius: 4,
          bodyFontStyle: "bold",
          callbacks: {
            title: () => {
              return "";
            },
            label: (tooltipItems, data) => {
              return tooltipItems.yLabel;
            }
          }
        },
        legend: {
          display: false
        },
        layout: {
          padding: {
            left: 0,
            right: 0,
            top: 0,
            bottom: 0
          }
        },
        scales: {
          yAxes: [
            {
              gridLines: {
                drawBorder: true,
                color: "pink",
                zeroLineColor: "pink"
              },
              ticks: {
                fontColor: "green",
                fontFamily: "Gamja Flower",
                fontSize: 10,
                fontStyle: "bold"
              }
            }
          ],
          xAxes: [
            {
              gridLines: {
                display: false
              },
              ticks: {
                fontColor: "blue",
                fontFamily: "Gamja Flower",
                fontSize: 12,
                fontStyle: "bold"
              }
            }
          ]
        },
        maintainAspectRatio: false,
        animation: false
      }}
      data={{
        labels: [
          "January",
          "February",
          "March",
          "April",
          "May",
          "June",
          "July"
        ],
        datasets: [
          {
            label: "dataset",
            fill: true,
            lineTension: 0,
            borderColor: "red",
            borderCapStyle: "butt",
            borderWidth: 1,
            borderJoinStyle: "miter",
            pointBorderColor: "red",
            pointBackgroundColor: "red",
            pointBorderWidth: 1,
            pointHoverRadius: 2.5,
            pointHoverBackgroundColor: "red",
            pointHoverBorderColor: "blue",
            pointHoverBorderWidth: 6,
            pointRadius: 1.5,
            pointHitRadius: 10,
            data: [65, 59, 80, 81, 56, 55, 40]
          }
        ]
      }}
    />
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
@bagratinho
Copy link
Author

awesomescreenshot-2018-09-07t20-27-45-379z

@Pringels Pringels added Awaiting Reproduction Bug needs to be reproduced. bug labels Dec 5, 2019
@Pringels Pringels added this to Needs triage in Bugfixing Dec 11, 2019
@dangreen
Copy link
Collaborator

dangreen commented Nov 1, 2021

Chart (canvas) should be initialized after the font is loaded. You can use this guide.

@dangreen dangreen closed this as completed Nov 1, 2021
Bugfixing automation moved this from Needs triage to Closed Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Reproduction Bug needs to be reproduced. bug
Projects
Bugfixing
  
Closed
Development

No branches or pull requests

3 participants