簡體   English   中英

用日期創建Flot折線圖

[英]Creating a Flot line chart with dates

我正在嘗試使用Flot創建折線圖,該折線圖在x軸上顯示月份和年份,並在y軸上顯示一個數字。

這是我的代碼:

var data= [];
var y = 1;
var x;  

var record=xmlDoc.getElementsByTagName("record");
for(i=0;i<record.length;i++)
{
    x = record[i].getElementsByTagName("date_of_consent")[0].childNodes[0].nodeValue;
    x = x * 1000
    y = y + i;
    newArray = [x, y];
    data.push(newArray);
}

    var dataset = [{label: "Enrollment Over Time",data: data}];

    var options = {
        series: {
            lines: { show: true },
            points: {
                radius: 3,
                show: false
            }
        }

    xaxis: {
        mode: "time",
        timeformat: "%y/%m"
    }
    };

    $(document).ready(function () {
        $.plot($("#flot-placeholder"), dataset, options);
    });

僅供參考,date_of_consent字段的值類似於此:1376092800000。問題似乎是將此數字轉換為日期。 我將不勝感激任何建議。 謝謝。

您有一個JavaScript語法錯誤:

var options = {
    series: {
        lines: { show: true },
        points: {
            radius: 3,
            show: false
        }
    }, <-- YOU ARE MISSING THIS COMMA!!
    xaxis: {
        mode: "time",
        timeformat: "%y/%m"
    }
};

在編寫代碼時,請經常檢查javascript控制台中是否有錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM