【问题标题】:Google Timeline chart: two horizontal axis谷歌时间线图表:两个横轴
【发布时间】:2016-10-06 11:47:27
【问题描述】:

大家好!

我使用时间线图来可视化我组织中的假期安排。 现在它看起来像这样: the bottom of the chart

var container = document.getElementById('chart');
        var chart = new window.google.visualization.Timeline(container);
        var dataTable = new window.google.visualization.DataTable();
 
        dataTable.addColumn({ type: 'string', id: 'Name' });
        dataTable.addColumn({ type: 'string', id: 'BarDates' });
        dataTable.addColumn({ type: 'date', id: 'Start' });
        dataTable.addColumn({ type: 'date', id: 'End' });
        dataTable.addColumn({ type: 'string', role: 'tooltip' });
        var beginStr = "";
        var endStr = "";
        for (var i = 0; i < rows.length; i++) {
            var elems = rows[i].split(',');
            var begin = new Date(elems[1]);
            beginStr = (begin.getDate() < 10 ? '0' + begin.getDate() : begin.getDate()) + '/' +
            (begin.getMonth() + 1 < 10 ? '0' + (begin.getMonth() + 1) : begin.getMonth() + 1);
            var end = new Date(elems[2]);
            endStr = (end.getDate() < 10 ? '0' + end.getDate() : end.getDate()) + '/' +
            (end.getMonth() + 1 < 10 ? '0' + (end.getMonth() + 1) : end.getMonth() + 1);
            if (beginStr === endStr) {
                isHidden = true;
            }
            if (elems.length > 1) {
                dataTable.addRow([elems[0], beginStr + ' - ' + en`enter code here`dStr, begin, end, elems[3]]);
            } else {
                count = elems[0] - 0;
            }
        }
 
        var options = {
            tooltip: { isHtml: true },
            timeline: {
                colorByRowLabel: true
            },
            width: $('#chart').width(),
            hAxis: {
                minValue: new Date(date - 0, 0, 0),
                maxValue: new Date(date - 0 + 1, 0, 0)
            },
            backgroundColor: '#fff'
        };
 
        $('#chart').height(count * 42 + 60);
      chart.draw(dataTable, options);

此外,月份名称还有一个非常奇怪的行为。他们正在将页面的每一次刷新都从英文名称更改为我的本地名称。

请帮我解决问题。

【问题讨论】:

    标签: javascript charts google-visualization timeline


    【解决方案1】:

    抱歉,我无法帮助你解决你的第一个问题,因为你没有以我能理解的方式陈述它。我认为问题出在问题标题中,但我不知道您的意思。

    对于第二个问题 - 语言选择 - 您可以明确告诉 Google Charts 在加载时使用特定的本地化。我不知道为什么会不一致。可以在此处找到设置语言的说明:

    https://developers.google.com/chart/interactive/docs/basic_load_libs#loadwithlocale

    为您希望使用的语言使用标准的 2 字母语言代码。例如:en=english、fr=french、ja=japanese。

    【讨论】:

    • 感谢您对我的第二个问题的回答。抱歉,我不清楚第一个问题。我试着改写它。我有沿 x 轴的标签(2 月、3 月、4 月等)。我希望它不仅在图表底部,而且在图表顶部。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多