Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents


English

Introduction

In this article, we will share how to start making an interactive EChart

...

where one can click a chart's bar to open another chart.

Getting Started

Advanced functionalities for userview components are done by adding code in their "Custom Footer". Usually placed in the "Advanced" section of most components. 

Image Modified

The code these sections accept are HTML code which has script tags that usually holds JavaScript code.

...

In order to edit or add any functionalities to your EChart, it needs to be declared. The Echart userview component will will have an ID created for you which can be referred to, and this ID can be found in the HTML element of the chart when launching the app, which is opened by:

  • Right-Clicking the chart → Inspect
  • Ctrl + Shift + I → Scroll through the developer tool and find the chart

Image Modified 


After finding the ID, you can then initialize it and declare it to a variable and only then you will have access to many of the chart's functionality and properties.

Code Block
languagexml
linenumberstruejs
<script>
$(document).ready(function() {
    //Declare the eChart
	var theChart = echarts.init(document.getElementById('echarts_3C18B399268D4E4593DED6E06FF03376'));
    });
});
</script>

...

A good starting point to make something interactable is to make it be able to detect a click!

Code Block
languagexml
linenumbersjstrue
    theChart.on('click', function(params) {
      	console.log("Click!");
    });

The code above is one way to make the chart react to being clicked!


Code Block
languagexml
linenumberstruejs
<script>
$(document).ready(function() {
    //Declare the eChart
	var theChart = echarts.init(document.getElementById('echarts_3C18B399268D4E4593DED6E06FF03376'));
    });

	//Detect click
     theChart.on('click', function(params) {
      	console.log("Click!");
    }); 
});
</script>

...

One simple interactive feature would be to make the user redirect to another site when they click on the EChart. The code below is an implementation of such.

Code Block
languagexml
linenumberstruejs
<script>
$(document).ready(function() {
    //Declare the eChart
	var theChart = echarts.init(document.getElementById([ID HERE]));
    });

	//Redirect after click
     theChart.on('click', function(params) {
     	url = "google.com";
     	document.location.href = url;
    }); 
});
</script>

Opening a Chart in a

...

Chart

An interactive EChart also has the ability to redirect the user to another chart, where the information in the other chart will dynamically change depending on which part of the EChart the user clicked.

Code Block
languagexml
linenumbersjstrue
<script>
$(document).ready(function() {
    //Declare the eChart
	var theChart = echarts.init(document.getElementById([ID HERE]));
    });

	//Redirect after click
    someCharttheChart.on('click', function(params) {
      	url = [OTHER CHART'S URL LINK] + "?" + params.name;
      	document.location.href = url;
    });
});
</script>

A way to make the other chart receive information is to bring it through the urlURL. By accessing accessing params' properties, it will have the property "name" which includes the name of the data the user has clicked on. This information can then be brought to the url URL as a parameter (usually separated with a '?')  which then the other chart can access.

To access the parameter in the urlURL, we can use hash variables to do so, more specifically, the hash variable #request.queryString#.

Below is an example code of using the hash variable, to see it's its full functionality and purpose, download the demo app

Code Block
languagesql


SELECT
	a.c_email as "Email",
	COUNT(a.c_email) as "Amount"
FROM
	app_fd_book_meeting_room a
JOIN
	app_fd_create_meeting_room b
ON
	a.c_room_id = b.id
WHERE
	b.c_room_ID = "#request.queryString#" and 
	a.c_status = "accept"
GROUP BY
	a.c_email, b.c_room_id

Download Demo

...

App

...