Change percentage legend colour of lightweight-charts-python

I was implementing lightweight-charts-python library that is python equivalent for tradingview’s lightweight-charts library.

In that I wanted to have a label showing open, high, low, close and percentage move of the candle that the crosshair was pointing to.

I found the way to add these labels from here but there was no way to change the colour of all labels or only the percentage label dynamically according to the crosshair’s candle’s colour.

Is there any workaround or a proper solution to this problem?

From what I can tell this color cannot be set dynamically from the outside.

A quick hack to get the desired behaviour:

  • Locate the func.js javascript file located in your local copy at lightweight_charts/js/funcs.js
  • Modify line 232 from
    let percent = `| ${percentMove >= 0 ? '+' : ''}${percentMove.toFixed(2)} %`
    

    to

    let percent = `| ${percentMove >= 0 ? '<span style="color: green">+' : '<span style="color: red">'}${percentMove.toFixed(2)} %</span>`
    

This should change the color of the percentage label dynamically from green (+) to red (-) (or any color of your choosing, if you have the css skills)

enter image description here

Leave a Comment