简体   繁体   English

自定义Google折线图

[英]Customize Google line chart

I am working on project that need a line chart and I chose Google line chart because that is easy to get and fast to use but I have problem with customizing some feature in Google line chart is there a way to can customize Google chart like the this image?? 我正在研究需要折线图的项目,因此我选择了Google折线图,因为它易于获取且使用快速,但是我在自定义Google折线图中的某些功能时遇到问题,是否可以像这样自定义Google图表图片?? I tried and use rotation but I didn't get the my outcome of that!!! 我尝试并使用轮换,但没有得到我的结果!!!
在此处输入图片说明

Here is the Google Line chart Sample Code 这是Google折线图示例代码

function drawChart() {
    var data = google.visualization.arrayToDataTable([
        ['X', 'Y'],
        [1, 100], // keep linked points adjacent
        [1, 200],
        [null, null], // insert blank row in between
        [2, 150],
        [2, 275],
        [null, null],
        [3, 75],
        [3, 200],
        [null, null],
        [4, 100],
        [4, 300]
    ]);
    var chart = new google.visualization.LineChart(document.querySelector('#chart_div'));
    chart.draw(data, {
        height: 400,
        width: 600,
        pointSize: 20,
        pointShape: 'triangle', rotation: 180
    });
}
google.load('visualization', '1', {packages:['corechart'], callback: drawChart});

You can do this by splitting your data points into separate series and drawing them with different point shape options: 您可以通过将数据点分成单独的系列并使用不同的点形状选项进行绘制来实现:

function drawChart() {
    var data = google.visualization.arrayToDataTable([
        ['X', 'Y', 'Direction'],
        [1, 100, 'down'], // keep linked points adjacent
        [1, 200, 'up'],
        [null, null, null], // insert blank row in between
        [2, 150, 'down'],
        [2, 275, 'up'],
        [null, null, null],
        [3, 75, 'down'],
        [3, 200, 'up'],
        [null, null, null],
        [4, 100, 'down'],
        [4, 300, 'up']
    ]);

    var view = new google.visualization.DataView(data);
    view.setColumns([0, 1, {
        // down triangles
        type: 'number',
        calc: function (dt, row) {
            return (dt.getValue(row, 2) == 'down') ? dt.getValue(row, 1) : null;
        }
    }, {
        // up triangles
        type: 'number',
        calc: function (dt, row) {
            return (dt.getValue(row, 2) == 'up') ? dt.getValue(row, 1) : null;
        }
    }]);

    var chart = new google.visualization.LineChart(document.querySelector('#chart_div'));
    chart.draw(view, {
        height: 400,
        width: 600,
        series: {
            0: {
                // this will draw the line
                pointSize: 0,
                color: '#3366cc' // set the color so they are all the same
            },
            1: {
                // this will draw the down triangles
                lineWidth: 0,
                pointSize: 20,
                pointShape: {
                    type: 'triangle',
                    rotation: 180
                },
                visibleInLegend: false,
                color: '#3366cc' // set the color so they are all the same
            },
            2: {
                // this will draw the up triangles
                lineWidth: 0,
                pointSize: 20,
                pointShape: {
                    type: 'triangle'
                },
                visibleInLegend: false,
                color: '#3366cc' // set the color so they are all the same
            }
        }
    });
}
google.load('visualization', '1', {packages:['corechart'], callback: drawChart});

http://jsfiddle.net/asgallant/6dhm8u3y/ http://jsfiddle.net/asgallant/6dhm8u3y/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM