svg - 使用 Google 图表工具的范围标记

标签 svg google-visualization

我试图在 Google Chart api 中突出显示图表的范围或区域。我需要线条和面积。我在已弃用的带有静态图像的 Google Chart 版本 ( link ) 中找到了它的文档,但我找不到任何有关如何在新版本中执行此操作的文档。这就是我想要实现的目标:

enter image description here

谢谢!

最佳答案

您需要使用 ComboChart 将多种不同类型的系列放入一个图表中。您需要一个“区域”系列来获得彩色区域。有几种不同的方法来获取垂直线,但考虑到您已经必须使用组合图来制作彩色区域,您不妨使用相同的技术来绘制垂直线。以下是创建如下图表的一些示例代码:

function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('number', 'X');
    data.addColumn('number', 'Y');
    data.addColumn('number', 'Area');
    data.addColumn('number', 'Vertical Line');
    data.addRows([
        [1, 5, null, null],
        [2, 4, null, null],
        [3, 6, null, null],
        [4, 2, null, null],
        [5, 2, null, null],
        [6, 5, null, null],
        [7, 8, null, null],
        [8, 9, null, null],
        [9, 3, null, null],
        [10, 6, null, null],
        // add data for the area background
        // start of area:
        [5, null, 0, null], // make sure the bottom value here is as low or lower than the min value you want your chart's y-axis to show
        [5, null, 10, null], // make sure the top value here is as high or higher than the max value you want your chart's y-axis to show
        // end of area:
        [8, null, 10, null], // use the same max value as the start
        [8, null, 0, null], // use the same min value as the start
        // add data for line:
        [3, null, null, 0], // use the same min value as the area
        [3, null, null, 10] // use the same max value as the area
    ]);

    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
    chart.draw(data, {
        height: 400,
        width: 600,
        series: {
            0: {
                type: 'line'
            },
            1: {
                // area series
                type: 'area',
                enableInteractivity: false,
                lineWidth: 0
            },
            2: {
                // vertical line series
                type: 'line',
                enableInteractivity: false
            }
        },
        vAxis: {
            viewWindow: {
                // you may want to set min/max here, depending on your data and the min/max used for your area and vertical line series
            }
        }
    });
}
google.load('visualization', '1', {packages: ['corechart'], callback: drawChart});

查看其工作情况:http://jsfiddle.net/asgallant/FEy4W/

关于svg - 使用 Google 图表工具的范围标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20112556/

相关文章:

html - 在 html 中渲染带有阴影的气泡状缩略图的灵活方法

javascript - 尽管 D3 map 位于我的网络服务器上,但它并未显示

SVG替代品?

google-visualization - 我们可以将 Google Chart Tools 与 Google Script HtmlService 一起使用吗

internet-explorer - Google Chart 未在 IE 中加载(但在隐身模式下加载)

javascript - Google Visualization 突出显示单条网格线

angular - Angular 中(单击)的样式绑定(bind)

javascript - 如何重复 SVG 多个部分的关键帧动画?

javascript - Google Charts 从 PHP Ajax 添加数据

javascript - 谷歌可视化数据表filterRows