3

A Custom Chart by Using the HTML Component Plainly Explained

 3 years ago
source link: https://hackernoon.com/a-custom-chart-by-using-the-html-component-plainly-explained-1h1y33ix
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Example Code

Home

0 reactions
let year = 2017;
let flights = {
	2014: [6.3, 2.4, 7.6, 5.4, 9.9, 7.8],
	2015: [6.7, 2.2, 11.2, 5.5, 10.1, 7.9],
	2016: [7.2, 3.1, 8.2, 5.6, 9.2, 10.2],
	2017: [7.4, 3.9, 8.8, 6.1, 8.7, 9.8]
};

$w.onReady(() =>{
	$w("#html1").postMessage(flights[year]);
	$w("#html1").onMessage((event)=>{

		if(event.data.type === 'ready'){
			$w("#html1").postMessage(flights[year]);
		}
		
		if(event.data.type === 'click'){
			$w("#clickedMessage").text = `The number of flights to ${event.data.label} in ${year} is ${event.data.value} million.`;
			$w("#clickedMessage").show();
		}
	});	
});

export function year_onChange(event) {
	year = $w('#year').value;
	$w("#html1").postMessage(flights[year]);
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK