【问题标题】:Google Charts - Area Chart Not Dividing Up Gridlines ProperlyGoogle Charts - 面积图未正确划分网格线
【发布时间】:2014-06-28 14:36:47
【问题描述】:

我试图创建一个 24 小时图,以度数显示每三小时的平均风向。我想让网格线以 45 度为增量,所以我指定了一个 viewWindow: {min: 0, max: 360}, gridlines: {count: 9}} 我希望在 0 处给我网格线, 45, 90, 135, 180, 225, 270, 315 和 360 但是由于某种原因,Google Charts 给了我 0, 40, 80, 120, 160, 200, 240, 280 和 320 的网格线,并且没有网格线即使点正在那里绘制,所有这些都在 360 度。我创建了工作代码的精简版:

`google.load("visualization", "1", {
    packages: ["corechart"]
});
google.setOnLoadCallback(wind_history_render);

function wind_history_render() {
    var wind_history_data = google.visualization.arrayToDataTable([
        ['Time', 'Direction'],
        ['00', 170],
        ['03', 190],
        ['06', 90],
        ['09', 360],
        ['12', 280],
        ['15', 300],
        ['18', 0],
        ['21', 320]
    ]);
    var wind_history_options = {
        title: 'Summit 24 Hour Wind History',
        width: '100%',
        height: '100%',
        legend: {
            position: 'none'
        },
        axisTitlesPosition: 'out',
        areaOpacity: 0.0,
        series: {
            0: {
                color: "purple",
                targetAxisIndex: 0,
                pointSize: 5,
                lineWidth: 0
            }
        },
        vAxes: {
            0: {
                title: 'Direction',
                titleTextStyle: {
                    color: 'purple',
                    italic: false,
                    bold: true
                },
                textStyle: {
                    bold: true
                },
                viewWindow: {
                    min: 0,
                    max: 360
                },
                gridlines: {
                    count: 9
                }
            }
        },
        hAxis: {
            textStyle: {
                bold: true
            }
        }
    };
    var windHistoryChart = new google.visualization.AreaChart(document.getElementById('windspeed-and-direction'));
    windHistoryChart.draw(wind_history_data, wind_history_options);
}`

这里有一个有效的 jsfiddle 示例:http://jsfiddle.net/rpushor88/K4Gnh/3/ 来演示发生了什么。我已经尝试在 IE 11 和 Chrome 版本 35.0.1916.153 m 中呈现它,这是撰写本文时的最新版本。

任何帮助将不胜感激

【问题讨论】:

    标签: javascript charts google-visualization area


    【解决方案1】:

    由于您确切知道希望网格线出现在哪些值上,因此最简单的方法是指定 vAxis.ticks 选项:

    vAxis: {
        ticks: [0, 45, 90, 135, 180, 225, 270, 315, 360]
    }
    

    例如:http://jsfiddle.net/asgallant/K4Gnh/7/

    【讨论】:

    • 谢谢您-这就是我一直在寻找的东西,但在我尝试时编码错误-最终编码为 'ticks: [{v: 0, f: 'N'}, {v: 45,f:'NE'},{v:90,f:'E'},{v:135,f:'SE'},{v:180,f:'S'},{v:225, f: 'SW'}, {v: 270, f: 'W'}, {v: 315, f: 'NW'}, {v: 360, f: 'N'}]' 完美风向图表
    猜你喜欢
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多