Can we customize the label color or font based on the value? - Official support forum | RGraph.net

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

Post a reply

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/yLjdqBoThis is an external link

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.

Post a reply

What's your name?
What do you want to say?