0

您好,提前感谢您的帮助、指导和鼓励。我是一名出色的编码员......主要是自学成才和半成功。

所以这里是挑战。我有一个浮点图,它有一个带有颜色样本、持久样本(它们不会关闭)、数据集切换和所有内容的定制图例。但是只有当我看到默认图例时才会出现样本。也就是说,我是否将图例设置为“显示:假”,样本也不会显示在我的自定义图例中。

有没有办法关闭/隐藏默认图例,但仍可以访问自定义图例可用的颜色托盘/色板?

这是代码块......它还有其他一些事情发生,其中一些我为了清楚起见而删掉了......

  var options = {
      yaxis: { min: 0 },
      xaxis: { tickDecimals: 0 },
      xaxes: [{
            axisLabel: 'Frequency (Hz)',
        }],
        yaxes: [{
        position: 'left',
        axisLabel: 'Power (dB)',
        }],
        series: {
                lines: {
                    lineWidth: 2,
                    show: true
                },
                points: {
                    show: false
                }
        },
        legend: {
            container: $("#labeler<?php echo $i ?>"),
            show: true,
            labelFormatter: function(label, series) {

         }
    },
    grid:{
        hoverable: true
       }

     };    

     var track = 0;
    // hard-code color indices to prevent them from shifting as
    // datasets are turned on/off
    var i = 0;
    $.each(datasets, function(key, val) {
        val.color = i;
        ++i;
    });

    // insert checkboxes 
    var choiceContainer = $("#choices<?php echo $i ?>");
     choiceContainer.append('<table><tr>');
    $.each(datasets, function(key, val) {
            track = track + 1;
            if (track == 1){
                choiceContainer.append('<td width=\"100\">Left Channel</td>');
            } else if(track == <?php echo $tracks ?>){
                choiceContainer.append('</tr><tr>');
                choiceContainer.append('<td>Right Channel</td>');
            }
            choiceContainer.append('<td width=\"45\"><input type="checkbox" name="' + key +
                               '" checked="checked" id="id' + key + '">' +
                               '<div style=\"width:18px; white-space:nowrap; float:left\"><bar /></div><label for="id' + key + '">'
                                + val.label + '</label></td>');


    });
    choiceContainer.append('</tr></table>');
    choiceContainer.find("input").change(plotAccordingToChoices);

    function plotAccordingToChoices() {
        var data = [];

        choiceContainer.find("input:checked").each(function () {
            var key = $(this).attr("name");
            if (key && datasets[key])
                data.push(datasets[key]);
        });

         if (data.length > 0){
             $.plot($("#placeholder<?php echo $i ?>"), data, options);
         }
    }
    plotAccordingToChoices();

        $('.legendColorBox > div').each(function(i){
            $(this).clone().prependTo(choiceContainer.find("bar").eq(i));
        });
4

1 回答 1

1

从您的代码看来,您正在将“自定义”图例附加到由 flot 构建的图例的克隆中。如果您禁用 flot 图例,那么您的 $('.legendColorBox > div') 选择器将找不到要克隆的任何内容。您可以破解它并在克隆后隐藏原始的 flot 图例,或者完全删除您对 flot 图例的要求。

要隐藏原始图例,只需执行以下操作:

$('.legend').eq(0).css('display','none');

在你的$.plot电话之后。

于 2013-10-12T13:57:58.210 回答