chartjs-chart-financial icon indicating copy to clipboard operation
chartjs-chart-financial copied to clipboard

[Bug] Data does not get displayed properly after hiding it and showing it again.

Open Grafnus opened this issue 3 years ago • 3 comments

I encountered a Bug where the financial chart would not display properly. I have appended some images: The images

I found this bug at the example here

Specs: Browser: Firefox 95.0.2 (32-bit) Extensions: uBlock Origins (Adblocker) (Both on and off) Operating system: Windows 10 Enterprise

Steps to reproduce:

  1. Hide the dataset by clicking on the label
  2. Show the dataset again by clicking on the label
  3. The bug is displayed in the graph

Grafnus avatar Jan 06 '22 06:01 Grafnus

Yeah I don't understand either why the exemple is bugged, it maybe needs an update 🤷‍♂️

camheras avatar Jan 06 '22 09:01 camheras

I haven't implemented the plugin into our page yet. Is the bug already fixed?

Grafnus avatar Jan 06 '22 09:01 Grafnus

@Grafnus I figured out why the behavior happens (wicks of the candles disappear when showing the candle after hiding them once) and what you can do to resolve it:

Why:

In this code: https://github.com/chartjs/chartjs-chart-financial/blob/master/src/element.candlestick.js#L15-L22 When you hide the dataset borderColors takes the value transparent and thus changes up, down and unchanged to transparent as well. It retains that value when you show the dataset again.

Resolution:

Explicitly set borderColor as a dataset property in your Chart, something like:

const chart = new Chart(chartContext, {
    type: chartType,
    data: {
      datasets: [{
          label: candlestickTitle,
          data: candlestickData,
          borderColor: {
            up: 'rgba(100, 150, 100, 1)',
            down: 'rgba(150, 100, 100, 1)',
            unchanged: 'rgba(100, 100, 100, 1)',
          },
          borderWidth: 1,
        },
...

This ensures that borders always have a color to display when showing the dataset again

abhinavsood avatar Aug 30 '22 17:08 abhinavsood