Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

The text isn't clean/sharp!

Open prateekkathal opened this issue 10 years ago • 18 comments

Hello,

I believe there is some issue with the text in my charts.

Ideally, a chart should look this way

screen_shot_2016-06-20_at_7 12 23_pm

But, in my case, the text seems to be blurry and too smooth. It doesn't look sharp/clean at all.

screen shot 2016-06-21 at 2 45 41 am

Following are the options I am using:

options: {
  animation: {
    duration: 5000,
    easing: "easeOutBounce"
  },
  tooltips: {
    mode: "label"
  },
  bar: {
    stacked: true
  },
  scales: {
    xAxes: [{
      gridLines: {
        display: false
      },
      ticks: {
        beginAtZero: true
      }
    }],
    yAxes: [{
      gridLines: {
        display: false
      },
      ticks: {
        beginAtZero: true,
        max: {!! ($individualStatsMax+1) !!},
      }
    }]
  },
  legend: {
    labels: {
      boxWidth: 10,
      fontSize: 14
    }
  }
}

Now, I understand the first image isn't ChartJs, so the font family can be different, but why is the text not sharp at all? Is this happening because of the theme I am using? If yes, what really can it be? Is there a way to fix this from ChartJs only?? If no, what else can be causing this?

Thanks,

prateekkathal avatar Jun 20 '16 21:06 prateekkathal

@prateekkathal This is due to the canvas rendering so its based on the browser / device and there is probably not much we can do at the moment. From http://stackoverflow.com/questions/4550926/subpixel-anti-aliased-text-on-html5s-canvas-element the fonts can be improved if the canvas context has no alpha channel

etimberg avatar Jun 21 '16 11:06 etimberg

@etimberg any news on this?

My chart too is looking blurry compared to other charts, ie. https://jsfiddle.net/askhflajsf/xzk6sh1q/ compared to https://coin.dance/volume/paxful/USD.

cc @prateekkathal

frankie-loves-jesus avatar Jun 07 '17 13:06 frankie-loves-jesus

Like @etimberg said, I believe this is a property of HTML5 canvas tag and so the ChartJs team isn't really able to do much about it.

Still, I would recommend you to have a look at this article - https://stackoverflow.com/questions/15661339/how-do-i-fix-blurry-text-in-my-html5-canvas

@etimberg If there is any scope of improvement in this, I think you should add some documentation on this regard on the main site.

CC: @frankie-loves-jesus

prateekkathal avatar Jun 07 '17 16:06 prateekkathal

I faced this today on Chrome latest version, literally wasted 3 hours to chase it. Finally it turned out that issue only occurs only when browser zoom is reduced less than 100%, resetting window zoom to 100% resolved the issue.

Hope this info helps the developers to reproduce and fix the bug!!!

kakasahebKK avatar Oct 27 '17 15:10 kakasahebKK

Had the same issue and tested different zooms. I have the blurry effects also with zoom > 100%. Only at 100% the chart is fine.

pierfreeman avatar Jan 23 '18 09:01 pierfreeman

https://github.com/apache/incubator-echarts/ which is also Canvas based, doesn't have this issue. I think there is something to be done here (yes I don't know what).

We can't expect the user to not use the zoom. Can you, at least, reopen it?

reda-alaoui avatar Jun 21 '18 18:06 reda-alaoui

Make sure that you don't adding some css to the canvas element. In my case I found that I am adding border property to the canvas element what was causing the problem of blur on text and bars.

dont use something like that :

`canvas { border: 1px solid #000 }`

or with id or class like that :

`#myChart { border: 1px solid #000 }`
`.myChart { border: 1px solid #000 }`

saidsoualhi avatar Nov 21 '18 15:11 saidsoualhi

Any hint on this? Changing the zoom to > 100% solves the problem, but the user must be able to handle the browser's zoom.

netishix avatar May 14 '19 06:05 netishix

@reda-alaoui can you share an example where echarts correctly handles the browser zoom != 100%?

I tried a few of their examples and it's doesn't behave better (actually worse for zoom > 100%)

image

@nahue086 We already adjust the scale of the canvas when the zoom is < 100% and I'm not sure what we can do better to make the text to appear sharp, neither if it's possible.

If anyone have a working (and clean) solution, feel free to open a PR.

simonbrunel avatar May 15 '19 13:05 simonbrunel

I've actually run into this. It's not just the text, but it's everything about the chart is not sharp. The issue is that we need to make all drawing straddle the pixels: https://stackoverflow.com/a/8696641/64421

benmccann avatar May 15 '19 14:05 benmccann

@benmccann agreed, it's not only the text but I don't understand how your comment (and solution) is related to this issue which is about the browser zoom? If I'm not wrong, we already straddle the pixels when drawing lines (e.g. when drawing scale lines using alignPixel).

simonbrunel avatar May 15 '19 14:05 simonbrunel

I noticed that when you don't straddle the pixels then adjusting the zoom in Chrome will often make things better. I don't have an explanation for why. I missed that this issue is about zooming making things worse

I wasn't aware of alignPixel. I think most places we don't use it. I wonder if we could use context.translate(0.5, 0.5) to make it substantially easier to straddle pixels rather than trying to manually add 0.5 to every location we do a drawing

benmccann avatar May 15 '19 15:05 benmccann

I notice the blurry charts in Firefox only, in Chromium they are crisp.

Edit:

I just ran into this CSS fix:

    #chartJS {
      image-rendering: optimizeSpeed;             /* Older versions of FF */
      image-rendering: -moz-crisp-edges;          /* FF 6.0+ */
      image-rendering: -webkit-optimize-contrast; /* Webkit (non standard naming) */
      image-rendering: -o-crisp-edges;            /* OS X & Windows Opera (12.02+) */
      image-rendering: crisp-edges;               /* Possible future browsers. */
      -ms-interpolation-mode: nearest-neighbor;   /* IE (non standard naming) */
    }

Source: https://stackoverflow.com/a/33161568

Edit2:

It is not a fix per se, but the charts look better when you do this on a MacBook Pro with Retina screen (touch bar)

abuisman avatar Feb 10 '20 21:02 abuisman

I had this and manually disabling, then reenabling the z-index on chartjs-size-monitor seemed to make it render properly. No idea why that works.

leacollaboro avatar Nov 17 '20 06:11 leacollaboro

My charts were also blurry. I noticed that if I disabled box-sizing: border-box (which was being applied by Bootstrap to all elements) then the charts were clear. So I added canvas: { box-sizing: initial; } to my CSS which solved the problem.

ryanhart2 avatar Nov 19 '20 14:11 ryanhart2

My charts were also blurry. I noticed that if I disabled box-sizing: border-box (which was being applied by Bootstrap to all elements) then the charts were clear. So I added canvas: { box-sizing: initial; } to my CSS which solved the problem.

See my answer here : https://stackoverflow.com/questions/33385398/how-to-fix-blurry-chart-issue-in-chart-js/53414863#53414863

saidsoualhi avatar Nov 19 '20 15:11 saidsoualhi

any new updates?

enkr1 avatar Nov 23 '21 07:11 enkr1

I am using chartjs v4 but still this issue persist, Is there any new update?

princekumar21 avatar Jun 04 '25 19:06 princekumar21