谷歌可视化仪表板中的TimeLine

时间:2014-04-11 19:18:42

标签: javascript jquery google-visualization bind annotatedtimeline

我有这个JSON代码:

{"cols":[{"label":"ID","type":"number"},
         {"label":"Naziv","type":"string"},
         {"label":"Vrsta","type":"string"},
         {"label":"Status","type":"string"},
         {"label":"Opis","type":"string"},
         {"label":"Pocetak","type":"date"},
         {"label":"Zavrsetak","type":"date"},
         {"label":"Odgovoran","type":"string"},
         {"label":"Parcela","type":"string"},
         {"label":"Usluzno?","type":"string"},
         {"label":"id_parcele","type":"string"}],
 "rows":[{"c":[{"v":1},{"v":"Priprema"},
               {"v":"navodnjavanje"},
               {"v":"U pripremi"},
               {"v":"Da se izrzi nadovdnjavanje"},
               {"v":"Date(2014, 02, 25)"},
               {"v":"Date(2014, 02, 28)"},
               {"v":"Laza Lazic"},
               {"v":"Njiva 5"},
               {"v":"NE"},
               {"v":"0"}]},
         {"c":[{"v":2},
               {"v":"Djubrenje"},
               {"v":"djubrenje"},
               {"v":"U toku"},
               {"v":"Vrsi se djubrenje parcele na temp. od oko 12C"},
               {"v":"Date(2014, 02, 28)"},
               {"v":"Date(2014, 03, 05)"},
               {"v":"Pera Peric"},
               {"v":"vocnjak 3"},
               {"v":"DA"},
               {"v":"0"}]},
         {"c":[{"v":34},
               {"v":"Hemijska analiza"},
               {"v":"odrzavanje, navodnjavanje, "},
               {"v":"U toku"},
               {"v":"Da se izvrsi hemijska analiza"},
               {"v":"Date(2013, 04, 25)"},
               {"v":"Date(2013, 04, 30)"},
               {"v":""},
               {"v":"Vocnjak N, Moja parcela N, "},
               {"v":""},
               {"v":"3, 11, "}]},
         {"c":[{"v":25},
               {"v":"sklas"},
               {"v":"obrada tla, zastita, skladistenje"},
               {"v":"U planu"},
               {"v":"testiranje"},
               {"v":"Date(2013, 04, 17)"},
               {"v":"Date(2013, 04, 30)"},
               {"v":""},
               {"v":"Vocnjak N, S4, Moja parcela N, Parcela 3n "},
               {"v":""},
               {"v":"3, 19, 11, 13"}]}
]}

所以“Pocetak”和“Zavrsetak”是一种日期类型。 (开始 - 结束日期)。我尝试使用下面的代码来显示TimeLine。

代码:

var timeline = new google.visualization.TimeLine({
    'chartType': 'TimeLine',
    'containerId': 'chart5',
    'cssClassNames': 'cssClassNames',
    'options': {
         cssClassNames: cssClassNames,
         allowHtml: true
    }
});

和offcource绑定时间轴:

bind([categoryPicker, stringFilter, stringFilter1, slider], [table, timeline]).

但不工作,我也没有任何错误。我只是看不到任何东西,没有桌子,没有时间表。 Witout时间轴代码一切正常。怎么解决这个问题。如何用对象显示时间轴?

1 个答案:

答案 0 :(得分:1)

首先,您需要使用ChartWrapper,而不是Timeline对象:

var timeline = new google.visualization.TimeLine(...);

应该是:

var timeline = new google.visualization.ChartWrapper(...);

然后,您需要在ChartWrapper的view.columns参数中设置用于时间轴的列:

var timeline = new google.visualization.ChartWrapper({
    chartType: 'Timeline',
    containerId: 'chart5',
    options: {
         // these options don't do anything in the Timeline chart
         cssClassNames: cssClassNames,
         allowHtml: true
    },
    view: {
        // as an example, use columns "Naziv", "Vrsta", "Pocetak", and "Zavrsetak" for the timeline
        columns: [1, 2, 5, 6]
    }
});