Legend text color in accordance with line color in jqplot

前端 未结 1 747
时光取名叫无心
时光取名叫无心 2020-12-18 16:06

I am using jqplot to draw multiple lines of different line colors.

Also, I have legends whose colors should be in accordance with the c

相关标签:
1条回答
  • 2020-12-18 16:44

    Taken from the question title I understand you want to change the color of legend labels to correspond to the color of series, right?

    For this reason, since the swatches which are just in front of the labels, we can use them to grab the color which we then set for the labels.

    This is the bit of the code you need. You need to remember to put it before you draw your plot.

    $.jqplot.postDrawHooks.push(function() {
        var swatches = $('table.jqplot-table-legend tr td.jqplot-table-legend-swatch');
        var labels = $('table.jqplot-table-legend tr td.jqplot-table-legend-label');
        labels.each(function(index) {
            //turn the label's text color to the swatch's color
            var color = $(swatches[index]).find("div div").css('background-color');
            $(this).css('color',color );
        });
    });
    

    You could see the code running live here.

    0 讨论(0)
提交回复
热议问题