Highcharts Demo

author(s): Torstein Hønsi

by vigneshwaranr

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="https://rawgithub.com/vigneshwaranr/highcharts_trendline/master/regression.js"></script>
<div id="container" style="height: 400px"></div>

JavaScript

function highcharts_line_intersect(line1_data, line2_data, user_options) {
    var opt = {
        /* The point object for the intersection points that will be appended to the line arrays.
         * By default the points will be inserted as [icptX, icptY]
         * 
         * You may customize this by setting it a point object {}.
         * Set any custom parameters except x and y which will be overridden with the intersection point
         * (Refer: http://api.highcharts.com/highcharts#series.data for the parameters supported by highcharts)
         */
        icptPoint: [],

        /* Override this method to customize the behavior
         * if the lines are parallel (never meets). 
         * 
         * (like =, ||, //)
         * 
         * Does not proceed further after this method is called.
         */
        onParallel: function () {
            console.log('Parallel lines can never meet');
        },

        /* Override this method to customize the behavior
         * if the lines already meet.
         * 
         * (like X, >, <)
         * 
         * Does not proceed further after this method is called.
         * 
         * @param icptX - intersection point X
         * @param icptY - intersection point Y         
         */
        onLinesAlreadyMeet: function (icptX, icptY) {
            console.log('Lines already meet at (' + icptX + ',' + icptY + ')');
        },

        /* Accepts a function that returns true or false
         * 
         * Use this to validate the intersection points before connecting the lines.
         *
         * For example, you might not want the connect the lines if the 
         * intersection is too far away.
         * 
         * Does not proceed further if the function does not return true
         * 
         * @param icptX - intersection point X
         * @param icptY - intersection point Y         
         */
        validateIntersection: function (icptX, icptY) {
            return true;
       ...