Vector plot

author(s): Torstein Hønsi

by Black Label

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/coloraxis.js"></script>
<script src="https://code.highcharts.com/modules/vector.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        A vector plot can visualize vectors using four values:
        The x and y coordinates, the length, and the angle. This 
        demo is showing a vector field, where vectors are given at
        regular intervals.
    </p>
</figure>

CSS

#container {
    height: 500px;
}

#csv {
	display: none;
}

.highcharts-figure, .highcharts-data-table table {
    min-width: 320px; 
    max-width: 700px;
    margin: 1em auto;
}

.highcharts-data-table table {
	font-family: Verdana, sans-serif;
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
	text-align: center;
	width: 100%;
	max-width: 500px;
}
.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}
.highcharts-data-table th {
	font-weight: 600;
    padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
    padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}
.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

JavaScript

Highcharts.chart('container', {

    title: {
        text: 'Highcharts Vector plot'
    },
    xAxis: {
        min: 0,
        max: 100,
        gridLineWidth: 1
    },
    yAxis: {
        min: 0,
        max: 100
    },
    series: [{
        type: 'vector',
        name: 'Sample vector field',
        colorKey: 'direction',
        data: [
        		{
            	x: 5,
              y: 5,
              length: 190,
              direction: 18,
              color: 'red'
              
            },
        		{
            	x: 65,
              y: 65,
              length: 190,
              direction: 234,
              color: 'orange'
            }
        ]
    }]

});

// The sample data was created using this formula:
/*
function generateData() {
    var data = [],
        x,
        y,
        length,
        direction;

    for (x = 5; x < 100; x += 5) {
        for (y = 5; y < 100; y += 5) {
            length = Math.round(200 - (x + y));
            direction = Math.round((x + y) / 200 * 360);
            data.push([
                x,
                y,
                length,
                direction
            ].join(', '));
        }
    }
    console.log('[\n    [' + data.join('],\n    [') + ']\n]');
}
generateData();
// */