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

How to make label font size responsive? #27

Closed
stmalk opened this issue Feb 2, 2018 · 1 comment
Closed

How to make label font size responsive? #27

stmalk opened this issue Feb 2, 2018 · 1 comment

Comments

@stmalk
Copy link

stmalk commented Feb 2, 2018

Hi, I'm trying to make both plugin data labels as well as X-Axis tick labels responsive so they change font size according to screen resolution. I couldn't find any solution to this issue and so far a simple bar chart does not resize properly as labels start to overlap and don't fit the boundaries.
I tried to change font size dynamically by adding a plugin:

plugins: [{
    beforeDraw: function(c) {
      var chartHeight = c.chart.height;
      c.scales['x-axis-0'].options.ticks.fontSize = chartHeight * 4 / 100;
    }
  }],

but it does nothing.

Is there any way to achieve that?

Thank you

Edit(SB): snippet has been moved in this jsfiddle

@simonbrunel
Copy link
Member

That should be easy for the data labels using scriptable options and context.chart.width (fiddle):

font: function(context) {
  var width = context.chart.width;
  var size = Math.round(width / 32);
    return {
      size: size,
      weight: 600
    };
}

However, this plugin don't deal with axis tick labels, you will have better results asking stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants