Python CGI script to show Google scatter chart with known trendline

245 views Asked by At

I am trying to make a Python CGI script show a Google ScatterChart with a linear trendline whose equation I can use elsewhere. The ScatterChart trendline option draws a trendline and I can find out the equation of the line by putting my pointer over the trendline, but that's no help because I need to get the coeffients from the equation programatically.

One solution I can think of is to write a function that computes the trendline and displays it on top of the ScatterChart. The problem here is that I don't know how to make a Google chart that has two series of data plotted differently (one series as dots, the other as a line).

A hybrid solution would be to use my function to compute the trendline so that I have the equation in my program, and then display the chart with its own Google-generated trendline. The issue here is that I know there is more than one way to make a linear trendline and I don't know which way Google uses.

1

There are 1 answers

0
asgallant On

Use the series..lineWidth option to make one series draw with a connecting line:

series: {
    0: {
        // scatter series
        lineWidth: 0
    },
    1: {
        // trendline
        lineWidth: 1,
        // control the point size of the trendline
        pointSize: 0,
        // set this if you don't want the points on the trendline to spawn tooltips
        enableInteractivity: false,
        // set this to remove the trendline from the legend
        visibleInLegend: false
    }
}