jQuery HeatMap: Legend Placement

Legend positions.

A live JavaScript/jQuery example of jqxHeatMap, the jQWidgets HeatMap component, with its complete source code below. It is one of 8 jqxHeatMap demos for jQuery.

jqxHeatMap API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxHeatMap shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxheatmap.js, jqxbuttons.js, jqxscrollbar.js, jqxlistbox.js, jqxdropdownlist.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    var xAxis = {
        labels: ['John', 'Marry', 'Alba', 'Steven', 'Josh', 'Alica', 'Robert', 'Kim', 'Ann', 'Paul', 'Regina', 'Dorothy']
    };
    var yAxis = {
        labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
    };

    var data = [
        [89, 39, 94, 55, 3],
        [53, 38, 26, 68, 33],
        [22, 0, 66, 90, 78],
        [97, 68, 68, 3, 99],
        [47, 47, 88, 6, 1],
        [73, 23, 3, 79, 100],
        [21, 86, 13, 33, 0],
        [53, 81, 95, 79, 66],
        [74, 68, 88, 51, 43],
        [10, 12, 78, 14, 21],
        [55, 58, 12, 82, 99],
        [88, 23, 86, 59, 53],
    ];

    $("#heatmap").jqxHeatMap({
        xAxis: xAxis,
        yAxis: yAxis,
        source: data,
        title: 'Car sales revenue per employee(in 1000 €)',
    });

    var source = ["Right", "Left", "Top", "Bottom"];

    $("#jqxdropdownlist").jqxDropDownList({
        source: source,
        width: '100px',
        selectedIndex: 0,
        autoDropDownHeight: true
    });

    $("#jqxdropdownlist").on('change', function (event) {
        var value = event.args.item.value;

        $("#heatmap").jqxHeatMap('setLegendPosition', value);
    });
});

body.html

<div id="heatmap"></div>

<div id="legend-position">
    <label for="jqxdropdownlist">Legend Position:</label>
    <div id="jqxdropdownlist"></div>
</div>

Learn more

More jQuery HeatMap demos