0

我需要知道如何使用 Flot 轻松地将另一个系列添加到现有绘图中。

这是我目前绘制单个系列的方式:

function sendQuery() {
    var host_name = $('#hostNameInput').val();
    var objectName = $('#objectNameSelect option:selected').text();
    var instanceName = $('#instanceNameSelect option:selected').text();
    var counterName = $('#counterNameSelect option:selected').text();
    $.ajax({
        beforeSend: function () {
            $('#loading').show();
        },
        type: "GET",
        url: "http://okcmondev102/cgi-bin/itor_PerfQuery.pl?machine=" + host_name + "&objectName=" + objectName + "&instanceName=" + instanceName + "&counterName=" + counterName,
        dataType: "XML",
        success: function (xml) {
            var results = new Array();
            var counter = 0;


            var $xml = $.xmlDOM(xml);
            $xml.find('DATA').each(function () {
                results[counter] = new Array(2);
                results[counter][0] = $(this).find('TIMESTAMP').text();
                results[counter][1] = $(this).find('VALUE').text();
                counter++;
            });

            plot = $.plot($("#resultsArea"), [{
                data: results,
                label: host_name
            }], {
                series: {
                    lines: {
                        show: true
                    }
                },
                xaxis: {
                    mode: "time",
                    timeformat: "%m/%d/%y %h:%S%P"
                },
                colors: ["#000099"],
                crosshair: {
                    mode: "x"
                },
                grid: {
                    hoverable: true,
                    clickable: true
                }

            });
4

2 回答 2

1

您可以添加另一个结果集:

// build two data sets
var dataset1 = new Array();
var dataset2 = new Array();

var $xml = $.xmlDOM(xml);
$xml.find('DATA').each(function(){
  // use the time stamp for the x axis of both data sets
  dataset1[counter][0] = $(this).find('TIMESTAMP').text();
  dataset2[counter][0] = $(this).find('TIMESTAMP').text();
  // use the different data values for the y axis
  dataset1[counter][1] = $(this).find('VALUE1').text();
  dataset2[counter][2] = $(this).find('VALUE2').text();
  counter++;
});

// build the result array and push the two data sets in it
var results = new Array();
results.push({label: "label1", data: dataset1});
results.push({label: "label2", data: dataset2});

// display the results as before
plot = $.plot($("#resultsArea"), results, {
  // your display options
});
于 2010-08-06T18:55:42.583 回答
0

在较高级别上,您调用 itor_PerfQuery.pl 的结果需要扩展以包含其他系列数据。然后,您需要将“结果”变量设为多维数组以支持附加数据,并且您需要更新当前的 xml“查找”循环,该循环会相应地填充结果。代码的其余部分应该与 flot 应该能够绘制扩展数据集相同。我认为对flot 示例的回顾会对您有所帮助。祝你好运。

于 2010-08-06T18:52:28.133 回答