Legend text color in accordance with line color in jqplot

最后都变了- 提交于 2019-12-18 05:24:09

问题


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

Also, I have legends whose colors should be in accordance with the corresponding line colors.

I seem to find no way to cope with the legend color.

So any hint?


回答1:


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.



来源:https://stackoverflow.com/questions/10424471/legend-text-color-in-accordance-with-line-color-in-jqplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!