How to use a "Select drop down menu" to trigger a change in a chart (chart.js)

3 replies · opened Oct 14, 2018

MmgirardOct 14, 2018

Hi,

When I select an item from a dropdown menu, I would like it to have an effect on my chart. Say if I select "Hawaii" from the drop down menu, I would like it to activate the "randomizeData" function. I have added the id="randomizeData" in the html drop down menu. And I believe I need to modify the function below.

The menu looks like this:

					<form action="#" method="post" class="nobottommargin">
						<div class="bottommargin-sm">
							<label for="">MENU</label>
							<select id="randomizeData" class="select-1 form-control" style="width:100%;">
								<optgroup label="Alaskan/Hawaiian Time Zone">
									<option value="AK">Alaska</option>
									<option value="HA">Hawaii</option>
								</optgroup>
								<optgroup label="Pacific Time Zone">
									<option value="CA">California</option>
									<option value="NV">Nevada</option>
								</optgroup>
								<optgroup label="Mountain Time Zone">
									<option value="AZ">Arizona</option>
									<option value="CO">Colorado</option>
								</optgroup>
								<optgroup label="Central Time Zone">
									<option value="AL">Alabama</option>
									<option value="AR">Arkansas</option>
								</optgroup>
								<optgroup label="Eastern Time Zone">
									<option value="CT">Connecticut</option>
									<option value="DE">Delaware</option>
								</optgroup>
							</select>
						</div>
					</form>

And I believe I need to modify this function from your code:

	document.getElementById('randomizeData').addEventListener('click', function() {
		config.data.datasets.forEach(function(dataset) {
			dataset.data = dataset.data.map(function() {
				return randomScalingFactor();
			});

		});

Any help or advice would be appreciated. Thank you.

MmgirardOct 14, 2018

HTML CODE


							
								MENU
								
									
										Alaska
										Hawaii
									
									
										California
										Nevada
									
									
										Arizona
										Colorado
									
									
										Alabama
										Arkansas
									
									
										Connecticut
										Delaware
									
								
							
						
MmgirardOct 14, 2018

JAVASCRIPT CODE

		document.getElementById('randomizeData').addEventListener('click', function() {
			config.data.datasets.forEach(function(dataset) {
				dataset.data = dataset.data.map(function() {
					return randomScalingFactor();
				});

			});
SSemicolon WebSTAFFOct 17, 2018

Hello,

Unfortunately, we currently do not provide Customization Services and custom support is not provided other than the Features included within the Template.

Consider changing the above code with the following:

document.getElementById('randomizeData').addEventListener('change'

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard