如何添加线性回归

时间:2015-01-29 05:11:48

标签: javascript

我正在尝试为我在jsfiddle中准备的数字添加一个线性回归。该图是一个简单的散点图,Id喜欢寻找趋势。我似乎无法获得回归线的代码......感谢您的帮助。

DEMO

$(function () {
    $('#container').highcharts({
        yAxis: {
            title: {
                text: "Obesity Rate (%)"
            }
        },
        xAxis: {
            title: {
                text: "Beer Consumed (gallons per capita)"
            }
        },
        chart: {
            type: 'bubble',
            zoomType: 'xy'
        },

        title: {
            text: 'How Beer Consumption and Cycling Influence Obesity Rates'
        },

        tooltip: {
            formatter: function () {
                return this.point.z + '</b> percent cycle/walk to work in <b>' + this.series.name;
            }
        },

        series: [{
            name: 'Alabama',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [30.2, 32.4, 3.4]
            ]
        }, {
            name: 'Alaska',
            color: 'rgba(253, 0, 255, 0.5)',
            data: [
                [28.7, 28.4, 8.9]
            ]
        }, {
            name: 'Arizona',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [29.5, 26.8, 3.2]
            ]
        }, {
            name: 'Arkansas',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.7, 34.6, 2.0]
            ]
        }, {
            name: 'California',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [25.5, 24.1, 3.8]
            ]
        }, {
            name: 'Colorado',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [30.0, 21.3, 4.3]
            ]
        }, {
            name: 'Connecticut',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [25.0, 22.1, 3.3]
            ]
        }, {
            name: 'Delaware',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [33.6, 31.1, 2.6]
            ]
        }, {
            name: 'Florida',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [27.4, 26.4, 2.2]
            ]
        }, {
            name: 'Georgia',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [25.7, 30.3, 1.8]
            ]
        }, {
            name: 'Hawaii',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [30.4, 21.8, 5.8]
            ]
        }, {
            name: 'Idaho',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [27.8, 29.6, 4.3]
            ]
        }, {
            name: 'Illinois',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [29.1, 29.4, 3.7]
            ]
        }, {
            name: 'Indiana',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [25.9, 31.8, 2.6]
            ]
        }, {
            name: 'Iowa',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [33.6, 31.3, 4.1]
            ]
        }, {
            name: 'Kansas',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [28.3, 30.0, 2.9]
            ]
        }, {
            name: 'Kentcuky',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [24.4, 33.2, 2.3]
            ]
        }, {
            name: 'Louisiana',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [33.9, 33.1, 2.4]
            ]
        }, {
            name: 'Maine',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [34.0, 28.9, 4.3]
            ]
        }, {
            name: 'Maryland',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [23.2, 28.3, 2.6]
            ]
        }, {
            name: 'Massachusetts',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.2, 23.6, 5.4]
            ]
        }, {
            name: 'Michigan',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.8, 31.5, 2.7]
            ]
        }, {
            name: 'Minnesota',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [28.5, 25.5, 3.5]
            ]
        }, {
            name: 'Mississippi',
            color: 'rgba(255, 204, 153, .5)',
            data: [
                [33.9, 35.1, 1.8]
            ]
        }, {
            name: 'Missouri',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [31.0, 30.4, 2.2]
            ]
        }, {
            name: 'Montana',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [41.0, 24.6, 6.2]
            ]
        }, {
            name: 'Nebraska',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [35.2, 29.6, 3.4]
            ]
        }, {
            name: 'Nevada',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [35.8, 26.2, 2.4]
            ]
        }, {
            name: 'New Hampshire',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [34.9, 26.7, 3.1]
            ]
        }, {
            name: 'New Jersey',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [22.4, 26.3, 3.5]
            ]
        }, {
            name: 'New Mexico',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [32.4, 26.4, 3.1]
            ]
        }, {
            name: 'New York',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [22.4, 25.4, 6.9]
            ]
        }, {
            name: 'North Carolina',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [27.1, 29.4, 2.0]
            ]
        }, {
            name: 'North Dakota',
            olor: 'rgba(255, 153, 51, .5)',
            data: [
                [45.8, 31.0, 4.4]
            ]
        }, {
            name: 'Ohio',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [30.1, 30.4, 2.6]
            ]
        }, {
            name: 'Oklahoma',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [28.3, 32.5, 2.1]
            ]
        }, {
            name: 'Oregon',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [30.3, 26.5, 6.2]
            ]
        }, {
            name: 'Pennsylvania',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [28.6, 30.0, 4.3]
            ]
        }, {
            name: 'Rhode Island',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.3, 27.3, 4.0]
            ]
        }, {
            name: 'South Carolina',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [32.7, 31.7, 2.3]
            ]
        }, {
            name: 'South Dakota',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [38.9, 29.9, 4.8]
            ]
        }, {
            name: 'Tennessee',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.2, 33.7, 1.5]
            ]
        }, {
            name: 'Texas',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [34.4, 30.9, 1.9]
            ]
        }, {
            name: 'Utah',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [20.2, 24.1, 3.5]
            ]
        }, {
            name: 'Vermont',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [35.3, 24.7, 6.5]
            ]
        }, {
            name: 'Virginia',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.7, 27.2, 2.7]
            ]
        }, {
            name: 'Washington',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [24.8, 27.2, 4.3]
            ]
        }, {
            name: 'West Virginia',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [30.3, 35.1, 3.0]
            ]
        }, {
            name: 'Wisconsin',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [26.2, 29.8, 4.0]
            ]
        }, {
            name: 'Wyoming',
            color: 'rgba(102, 255, 102, .5)',
            data: [
                [33.0, 27.8, 4.3]
            ]
        }]
    });
});

0 个答案:

没有答案