1

jqplot用来绘制多条不同线条颜色的线条。

另外,我有图例,其颜色与相应的线条颜色一致。

我似乎没有办法应对传奇色彩。

那么有什么提示吗?

4

1 回答 1

3

取自问题标题,我了解您想将图例标签的颜色更改为与系列的颜色相对应,对吗?

出于这个原因,由于样本就在标签前面,我们可以使用它们来获取我们为标签设置的颜色。

这是您需要的代码。在绘制情节之前,您需要记住放置它。

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

你可以在这里看到实时运行的代码。

于 2012-05-03T09:31:24.507 回答