2

谷歌折线图中,你如何使系列线虚线?

例如下面屏幕截图中的红线(称为“B 行”)?

在此处输入图像描述

下面是我非常简单的测试代码,只需在浏览器中打开它就可以立即运行。

请注意添加确定性角色的通常建议:

    {"p":{"role":"certainty"},"label":"Dashed","type":"boolean"}

在这里没有帮助,因为它会使两条线(行“A”和“B”)变成虚线(部分)。

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script>
<script type="text/javascript">

        var data = {"rows":[
        {"c":[{"v":"C"},{"v":-43},{"v":-42}]},
        {"c":[{"v":"D"},{"v":-49},{"v":-39}]},
        {"c":[{"v":"E"},{"v":-49},{"v":-48}]},
        {"c":[{"v":"F"},{"v":-50},{"v":-49}]},
        {"c":[{"v":"G"},{"v":-57},{"v":-56}]}],

        "cols":[
        {"p":{"role":"domain"},"label":"MEASUREMENT","type":"string"},
        {"p":{"role":"data"},"label":"Row A","type":"number"},
        {"p":{"role":"data"},"label":"Row B","type":"number"}]};

        function drawCharts() {
            var x = new google.visualization.DataTable(data);

            var options = {
                title: 'How to make red line dashed?',
                width: 800,
                height: 600
            };

            var chart = new google.visualization.LineChart(document.getElementById('test'));
            chart.draw(x, options);
        }

        $(function() {
            google.setOnLoadCallback(drawCharts);
        });

</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
4

1 回答 1

2

这是一个使用确定性角色的示例。有什么理由不适合你吗?

google.load('visualization', '1', {
    packages: ['corechart'],
    callback: drawVisualization
});

var data = {
    "rows": [
      {"c": [{"v": "C"}, {"v": -43}, {"v": -42}, {"v": false}]},
      {"c": [{"v": "D"}, {"v": -49}, {"v": -39}, {"v": false}]},
      {"c": [{"v": "E"}, {"v": -49}, {"v": -48}, {"v": false}]},
      {"c": [{"v": "F"}, {"v": -50}, {"v": -49}, {"v": false}]},
      {"c": [{"v": "G"}, {"v": -57}, {"v": -56}, {"v": false}]}],

    "cols": [
      {"p": {"role": "domain"},"label": "MEASUREMENT","type": "string"},
      {"p": {"role": "data"},"label": "Row A","type": "number"},
      {"p": {"role": "data"},"label": "Row B","type": "number"},
      {"p": {"role": "certainty"},"type": "boolean"}]
};

function drawVisualization() {
    var x = new google.visualization.DataTable(data);

    var options = {
        title: 'How to make red line dashed?',
        width: 800,
        height: 600
    };

    var chart = new google.visualization.LineChart(document.getElementById('visualization'));
    chart.draw(x, options);
}

这是一个使用确定性角色使两条线都变成虚线的示例。

google.load('visualization', '1', {
    packages: ['corechart'],
    callback: drawVisualization
});

var data = {
    "rows": [
      {"c": [{"v": "C"}, {"v": -43}, {"v": false}, {"v": -42}, {"v": false}]},
      {"c": [{"v": "D"}, {"v": -49}, {"v": false}, {"v": -39}, {"v": false}]},
      {"c": [{"v": "E"}, {"v": -49}, {"v": false}, {"v": -48}, {"v": false}]},
      {"c": [{"v": "F"}, {"v": -50}, {"v": false}, {"v": -49}, {"v": false}]},
      {"c": [{"v": "G"}, {"v": -57}, {"v": false}, {"v": -56}, {"v": false}]}],

    "cols": [
      {"p": {"role": "domain"},"label": "MEASUREMENT","type": "string"},
      {"p": {"role": "data"},"label": "Row A","type": "number"},
      {"p": {"role": "certainty"},"type": "boolean"},
      {"p": {"role": "data"},"label": "Row B","type": "number"},
      {"p": {"role": "certainty"},"type": "boolean"}]
};

function drawVisualization() {
    var x = new google.visualization.DataTable(data);

    var options = {
        title: 'How to make red line dashed?',
        width: 800,
        height: 600
    };

    var chart = new google.visualization.LineChart(document.getElementById('visualization'));
    chart.draw(x, options);
}
于 2013-06-26T13:48:42.180 回答