HELP!!! - Displaying multiple trend lines in a ScatterChart...

19 views
Skip to first unread message

Jose Ramos

unread,
May 29, 2020, 2:09:33 PM5/29/20
to Google Chart API
I am trying to display two trend lines Using a ScatterChart visualization with two trendlines, but nothing displays.
1. Is this even supported by the API?
2. If it is, what is wrong with my code?

Here's the code:

<html>
<head>
    <title>Google Charts Tutorial</title>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.charts.load('current', { 'packages': ['corechart'] });
    </script>
</head>

<body>
    <div id="emblem" style="width: 100%; height: 75px;"></div>
    <div id="graph_container" style="width: 100%; height: 500px"></div>

    <script language="JavaScript">
        function drawChart()
        {
            // Define the chart to be drawn.
            var data = new google.visualization.DataTable();
            data.addColumn('number', 'Year');
            data.addColumn('number', 'Rate');

            data.addRows([
                [2018, 9.60, 8.60],
                [2019, 9.79, 8.79],
                [2020, 10.08, 9.08],
                [2021, 10.38, 9.38],
                [2022, 10.69, 9.69]
            ]);    

            // Set chart options
            var options =
            {
                title: 'Activity Rates',
                hAxis: { title: 'Year', format:'0' },
                vAxis: { title: 'Activity Rate' },
                legend: 'none',
                backgroundColor: 'transparent',
                trendlines: { 0: { color: 'red' }, 1: { color: 'blue' } },
isStacked: true
};

            // Instantiate and draw the chart.
            var chart = new google.visualization.ScatterChart(document.getElementById('graph_container'));
            chart.draw(data, options);
        }
        google.charts.setOnLoadCallback(drawChart);
    </script>
</body>
</html>

Thanks!!
Reply all
Reply to author
Forward
0 new messages