Successfully!

Error!

JS Synchronous Display of Map and Chart Tooltips

  • Last update:  2020-12-16
  • I. Overview

    When the map automatically displays the tooltip of each area, other charts also display the data of the corresponding area, as shown in the following figure:

    1606448220348879.gif

    II. Example

    2.1 New dataset

    Create a new dashboard and create a new Embedded dataset, as shown in the following figure:

    1606448219524669.png


    2.2 Chart settings

    1) Add 2 charts: a map and a column chart, as shown below:

    1606448273782277.png

    2) Set the data and attributes for the column chart and map, as shown in the figure below:

    Map

    1606448315314622.png

    Bar chart

    1606448315715285.png


    1606448381900285.png

    1606448381761334.png

    1606448475456810.png


    2.3 Add event

    Select body from the component list, and add an After Initialization event.

    In the event definition window, create a new parameter named area, and the parameter value uses the formula: Embedded1.select(country)

    As shown below:

    1606448508826643.png


    1606448507432407.png

    The JS code of the event is as follows:

    window.area = area;
    window.temp = 0;
    var len = window.area.length;
    var temp = 0;
    setTimeout(function () {
        var vanchart = FR.Chart.WebUtils.getChart('chart0').vanCharts.charts[0];
        //Get the map series and all data points
        var series = vanchart.series,
            allPoints = [];
        for (var i = -1; ++i <series.length;) {
            allPoints = allPoints.concat(series[i].points);
        }
        setInterval(function () {
            // Update the column chart, assign the current map point to the area parameter of the column chart
            FR.Chart.WebUtils.changeParameter(
                'chart1', {
                    'area': window.area[window.temp]
                }
            );      
            // The map displays the data point currently looped to
            for (var j = 0; j <allPoints.length; j++) {
                if (allPoints[j].name == window.area[window.temp]) {
                    vanchart.showTooltip(allPoints[j]);
                }
            }
            // window.temp is the serial number of currently displayed map data point
            // Every time the data of one area is displayed, window.temp is increment by 1, so the next area will be displayed in the next loop
            // When it is the final map point, window.temp is reset to display the first map point
            if (window.temp == (window.area.length-1)) {
                window.temp = 0;
            } else {
                window.temp = window.temp + 1;
            }
        }, 2000); //Interval of the loop is 2000 milliseconds, so the next map point will be displayed every 2 seconds
    }, 1000)


    2.4 Preview effect

    Save the template and preview. The effect is as shown in the beginning.

    Note: Mobile terminal is not supported.

    III. Completed Template

    Attachment List


    Theme: Dashboard
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    Doc Feedback