About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 15 years old) and has a wealth of features making it an ideal choice to show charts on your website.

More »

 

Download
Get the latest version of RGraph (version 6.17) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

Can we customize the label color or font based on the value?


Posted by Ananth at 15:51 on Thursday 20th October 2022 [link]
can we customize datalable color or font based on Number?

e.g., if we have 0 (Zero) color will be white and for greater than 0 it will be on black etc?


new RGraph.Bar({
    id: 'cvs2dr',
    data: [1, 0, 8, 4, 6, 3, 1, 5, 7, 8, 4, 6],
    data: dRej,
    options: {
        xaxisLabels: dR,
        labelsAbove: true,
        title: 'DRR',
        xaxisTickmarksCount: 0,
        xaxisLinewidth: 3,
        yaxis: false,
        colors: ['#FF0000', '#54A4CF'],
        backgroundGridVlines: false,
        backgroundGridHlines: false,
        backgroundGridBorder: false,
        titleSize: 12,
        tooltipsPointer: false,
        tooltipsPositionStatic: false,
        tooltipsCss: {
            fontSize: '10pt',
            border: '5px solid #666',
            textAlign: 'left',
            pointerEvents: 'none',
        },
        tooltipsEffect: 'none',
        tooltipsEvent: 'mousemove'
    },
}).draw().responsive([
    { maxWidth: null, width: 600, height: 250, options: { textSize: 8 }, parentCss: { 'float': 'right' } },
    { maxWidth: 800, width: 350, height: 200, options: { textSize: 12 }, parentCss: { 'float': 'none', textAlign: 'center' } }
]);

Posted by Richard at 16:50 on Thursday 20th October 2022 [link]
I was all ready to say "That would be rather involved" and then I realised that you're probably referring to the X-axis labels - not the Y axis labels. This makes it somewhat easier.

There's still nothing built-in that will do what you want, but what you can do, is use the draw event to have some custom code run to draw the labels yourself and this way you can determine the color based on the data.

I've made you a demo here:

https://codepen.io/rgraph/full/yLjdqBo

If you want to omit the label though you could just not draw it at all or set the color to transparent, Otherwise I'd choose a different color.

[Replies are now closed]