图例文字颜色与jqplot中的行颜色一致 [英] Legend text color in accordance with line color in jqplot

查看:77
本文介绍了图例文字颜色与jqplot中的行颜色一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqplot绘制多条具有不同线条颜色的线条.

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.

有什么提示吗?

推荐答案

从问题标题中得知,我知道您想更改图例标签的颜色以与系列的颜色相对应,对吗?

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 );
    });
});

您可以在此处看到正在运行的代码.

这篇关于图例文字颜色与jqplot中的行颜色一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆