道场图表。 X轴标签不是连续顺序

时间:2015-08-17 21:33:43

标签: javascript charts dojo line

我有一个图表,其中X轴从SQL表中的单元格中提取数据。 SQL表的源数据单元格式为DATE。 SQL单元格格式为DATETIME。当数据导出到.csv时,单元格格式再次为DATE,并且.csv中构建的图表具有按顺序日期顺序的X轴。当在GIS上的图表中查看相同的数据时,X轴日期无序,使得绘制的数据无法破译。这是图表的代码。任何帮助将不胜感激。感谢。

function makeChart(featureset){

dojo.empty("chartDiv");

var dlg = dijit.byId('chartDialog');

// When resources are loaded and the DOM is ready....
dojo.ready(function () {
    var data = featureset._jsonData.items;
    var store = new dojo.data.ItemFileWriteStore({
        data: {
            identifier: "TestID",
            label: "Parameter",
            items: data
        }
    });

    chart = new dojox.charting.DataChart("chartDiv", {
        comparative: true
        //scroll:stretchToFit
    });
    chart.setStore(store, { Parameter: '*' }, "Result");
    //chart.addAxis("x", {title: "Sample#", titleOrientation: "away", majorLabels:true, minorTicks:true, minorLabels:true,
            if (data.length > 2) {
        chart.addAxis("x", {
            title: "Collection Date",
            titleOrientation: "away",
            majorTicks: false,
            majorLabels: true,
            majorTickStep: 5,
            minorTicks: false,
            from: 0, to: (data.length + 0.5),
            labelFunc: function (n) {
                // I am assuming that your timestamp needs to be multiplied by 1000. 
                //var date = new Date(parseInt(data[n].CollectionDate) * 1000);
                var date = data[n].CollectionDate;
                return date;


            }
        });
    }
    chart.addAxis("y", { vertical: true });

    var c = dojo.connect(chart, "onData", function () {
        dojo.disconnect(c);
        if (dijit.byId("chartlegend")) {
            dijit.byId("chartlegend").destroy();
            dojo.create("div", { id: "chartlegend" }, "chLegHd");
            chlegend = new dojox.charting.widget.Legend({ chart: chart }, "chartlegend");
        }
        else {
            chlegend = new dojox.charting.widget.Legend({ chart: chart }, "chartlegend");
            chlegend.startup();
        }
    });
});

dlg.show();

}

2 个答案:

答案 0 :(得分:0)

我从数据类型" datetime"更改了源单元格到"约会"这对图表的显示方式没有任何影响。它应显示连续日期,即6/14/2015 7/01/2015 8/13/2015

但它正在显示8/13/2015 7/01/2015 6/14/2015

答案 1 :(得分:0)

我不太清楚我非常清楚地理解你的问题。您希望按照从DB检索的顺序显示日期。您可以这样做:

您可以通过检索到的数据库数据创建标签数组。

var dBDateArray= ["array of dates from the DB in sequential order"];
var labelsArray = [];

for (var i = 0; i < dBDateArray.length; i++,) {
    var obj = {};
    obj.value = i;
    obj.text = dbDateArray[i].name;
    labelsArray.push(obj);
}

x轴中的标签设置为this.labelsArray

this.chart1.addAxis("x", {
title: "Collection Date",
titleOrientation: "away",
labels:labelsArray
})