。我的意圖是繪製音頻功率譜數據,包括曲線上每個軌道的兩個通道。所以我可以預期在一場音樂會上有2到40行。flot.js情節與複選框和顏色的色板我特別使用海軍報繪製代碼不工作
我希望有開啓和關閉每條線路的方法,同時保持對劇情靜態數字和顏色。我已經嘗試了各種方法,有兩個幾乎得到的地方,我想:
首先是基於http://people.iola.dk/olau/flot/examples/turning-series.html的代碼,如下圖所示:
var track = 0;
// hard-code color indices to prevent them from shifting as
// countries 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=\"35\"><input type="checkbox" name="' + key +
'" checked="checked" id="id' + key + '">' +
'<label for="id' + key + '">'
+ val.label + '</label></td>');
});
choiceContainer.append('</tr></table>');
choiceContainer.find("input").click(plotAccordingToChoices);
function plotAccordingToChoices() {
var data = [];
choiceContainer.find("input:checked").each(function() {
var key = $(this).attr("name");
if (key && datasets[key])
data.push(datasets[key]);
});
var options = {
yaxis: { min: 0 },
xaxis: { tickDecimals: 0 },
xaxes: [{
axisLabel: 'Frequency (Hz)',
}],
yaxes: [{
position: 'left',
axisLabel: 'Power (dB)',
}],
series: {
lines: {
lineWidth: 2
}
},
legend: {
noColumns:7,
container: $("#labeler<?php echo $i ?>"),
labelFormatter: function(label, series){
return '<a href="#" onClick="togglePlot('+series.idx+'); return false;">'+label+'</a>';
}
}
};
if (data.length > 0){
$.plot($("#placeholder<?php echo $i ?>"), data, options);
}
}
plotAccordingToChoices();
這個偉大的工程爲我我試圖完成,除了checkboxes
不顯示旁邊的色樣...
這裏的示例:http://jsfiddle.net/mpazaryna/Zvqqn/顯示了一個代碼,它可以非常簡單地使用色樣創建開關功能。但不適於本身(IMHO)到格式化出的圖例中的方式被選擇到哪個信道和哪一個磁道是相干的。
所以,我的目標是找到一種方法,將色板添加到現有的代碼,上面,因爲這是目前的方式,我覺得到頁面的佈局有利於結構。
類似的帖子這個我覺得有你要找的http://stackoverflow.com/questions/4230945/flot-graph-use-legend-to-turn-on-off-series解決方案 –
斯蒂芬,這是類似的,我想看看它是否解決了我的問題目前。感謝指針! – Mark