Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a Google line chart with vertical divider?

I have several google line charts (actually, combocharts with both linecharts and areacharts inside) that need to have a vertical "before&after" kind of marker, something like this: enter image description here

how do I do this?

I see in the docs that I can customize a single point in line (like make it a big star) to serve as a marker, but if there's a way to do this with a vertical line, that would be much better.

like image 479
kurtgn Avatar asked Jan 28 '16 04:01

kurtgn


People also ask

How do you insert a vertical divider in Google Sheets?

Open the Format menu. Press Columns > More Options. Choose the number of columns you want and ensure that Line Between Columns is checked. Click Apply—your text will appear in columns with a vertical line between them.

How do I add a vertical line in Google Sheets chart?

Google Sheets does not have a built-in feature to add a vertical line directly to your graph. However, users can use a workaround that converts a second series into a vertical line. This workaround involves adding a new column to your dataset specifically for this marker.


1 Answers

Found this somewhere

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

function drawVisualization() {
    // example copied from Google Visualization API playground,
    // modified for category axis annotations

    // Create and populate the data table.
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'x');
    data.addColumn({type: 'string', role: 'annotation'});
    data.addColumn({type: 'string', role: 'annotationText'});
    data.addColumn('number', 'Cats');
    data.addColumn('number', 'Blanket 1');
    data.addColumn('number', 'Blanket 2');
    data.addRow(["A", null, null, 1, 1, 0.5]);
    data.addRow(["B", null, null, 2, 0.5, 1]);
    data.addRow(["C", null, null, 4, 1, 0.5]);
    data.addRow(["D", null, null, 8, 0.5, 1]);
    data.addRow(["E", null, null, 7, 1, 0.5]);
    data.addRow(["F", null, null, 7, 0.5, 1]);
    data.addRow(["G", 'Foo', 'Foo annotation', 8, 1, 0.5]);
    data.addRow(["H", null, null, 4, 0.5, 1]);
    data.addRow(["I", null, null, 2, 1, 0.5]);
    data.addRow(["J", null, null, 3.5, 0.5, 1]);
    data.addRow(["K", 'Bar', 'Bar annotation', 3, 1, 0.5]);
    data.addRow(["L", null, null, 3.5, 0.5, 1]);
    data.addRow(["M", null, null, 1, 1, 0.5]);
    data.addRow(["N", null, null, 1, 0.5, 1]);

    // Create and draw the visualization.
    new google.visualization.LineChart(document.getElementById('visualization')).
    draw(data, {
        curveType: 'function',
        width: 500,
        height: 400,
        vAxis: {
            maxValue: 10
        },
        annotations: {
            style: 'line'
        }
    });
}

http://jsfiddle.net/NC37X/

This answers my question.

like image 130
kurtgn Avatar answered Sep 30 '22 15:09

kurtgn