score:1
Your approach is wrong, because you are assigning the id to div after the all JavaScript was loaded, so the files displaying graphs in specific id will not render. There must be ID present while the js/example1.js is loading.
You would either need to load both graphs in hidden divs and show the div on click as example bellow. Or on click load specific script via ajax call.
$(document).on('click', '.button', function(){
$('.button').removeClass('is-success');
$(this).addClass('is-success');
$('#container-'+ this.id).toggle();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<nav class="navbar has-shadow">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="#"><img src="./img/logo.png" alt=""></a>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">About</a>
<div class="navbar-dropdown">
<a href="documentation.html" class="navbar-item"><span class="icon"><i class="fas fa-book"></i></span><span class="name">Documentation</span></a>
</div>
</div>
</div>
</div>
</div>
</nav>
<div class="columns" id="">
<aside class="column is-2 aside hero is-fullheight">
<div>
<div class="main">
<a href="index.html" class="item"><span class="icon"><i class="fas fa-home"></i></span><span class="name">Home</span></a>
</div>
</div>
</aside>
<div class="column is-1 is-fullheight" id="" style="border:1px solid black;">
<section class="section">
<div class="contain" >
<p class="field"><span class="button is-dark is-small" id="example1">Example1</span></p>
<p class="field"><span class="button is-dark is-small" id="example2">Example2</span></p>
</div>
</section>
</div>
<div class="column is-9 is-fullheight" id="" style="border:1px solid red;">
<section class="section">
<div class="content" style="border:1px solid green;">
<div id="container-example1" style="display:none">Loaded Graph 1</div>
<div id="container-example2" style="display:none">Loaded Graph 2</div>
</div>
</section>
</div>
</div>
</body>
For the ajax load of script you could go with something like this, can't test it as I don't have your example files, but it should at least point you right direction.
$(document).on('click', '.button', function() {
$(".group").attr("id", "#container-" + this.id) //add id - must be before script loads/runs
$.getScript('js/' + this.id + '.js') //load script with the same name as id
.done(function() { //if loaded correctly
$('.button').removeClass('is-success');
$(this).addClass('is-success');
$(".group").css("display", "block"); //show chart
})
.fail(function() {
/* do something when loading fails*/
});
})
<body>
<nav class="navbar has-shadow">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="#"><img src="./img/logo.png" alt=""></a>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">About</a>
<div class="navbar-dropdown">
<a href="documentation.html" class="navbar-item"><span class="icon"><i class="fas fa-book"></i></span><span class="name">Documentation</span></a>
</div>
</div>
</div>
</div>
</div>
</nav>
<div class="columns" id="">
<aside class="column is-2 aside hero is-fullheight">
<div>
<div class="main">
<a href="index.html" class="item"><span class="icon"><i class="fas fa-home"></i></span><span class="name">Home</span></a>
</div>
</div>
</aside>
<div class="column is-1 is-fullheight" id="" style="border:1px solid black;">
<section class="section">
<div class="contain">
<p class="field"><span class="button is-dark is-small" id="example1">Example1</span></p>
<p class="field"><span class="button is-dark is-small" id="example2">Example2</span></p>
</div>
</section>
</div>
<div class="column is-9 is-fullheight" id="" style="border:1px solid red;">
<section class="section">
<div class="content" style="border:1px solid green;">
<div class="group" id="" style="display: none;"></div>
</div>
</section>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</body>
score:0
You can use this:
var my_id = 2;
$("#container-example"+my_id).css("display","block");
Source: stackoverflow.com
Related Query
- Set ID to div and show the div after clicking a button using jquery
- How to set json data from url on highchart and polling the json data after 1 sec to dislay on highchart using Angular js
- How to make two charts using highchart show up in the same line side by side using div
- Change the legend in highcharts heatmap to show instead of a color bar, a set of fixed icons with hide and show on click
- I want to capture the starting and end point of all the series in my multigraph and show it in a table using MeasureX of StockTools in Highstock
- Why would the label of the vertical axis only show after the button is clicked?
- Highcharts is not displaying in the div at all, resulting in a blank page - Using python flask and jinja template?
- Using the source version instead of mimified when import lib with reactjs and npm
- How to set reset zoom button and title to exactly center of the high charts
- Updating the axis of a highcharts chart object using jquery after inital render (django)
- I cannot pass in a variable into the highcharts function using jquery and pug.
- How to display the value instead of percentage in a pie chart using jquery Highcharts
- Loading Highcharts via shim using RequireJS and maintaining jQuery dependency
- Show specific series values in the stack label using highcharts
- Using Highcharts and displaying a message over or on the chart when there is no data
- Convert hours and minute to millisecond using javascript or jQuery
- AngularJS and angular-translate: Using the translate filter in an object literal
- drilldown maps and funnell charts on the same page using highcharts
- Highcharts: set 'select' state on a point and maintain it after mouseover?
- Toggle the custom button text using highcharts
- How to set series-label to false by default and change the color of series label text in highchart
- Highcharts show the same yAxis start and end value with multiple data series
- Highcharts visualizes chart data incorrectly after zooming or using the navigator
- How to show plotlines on highstock when its set much higher than the data series?
- Highcharts - Why is there extra spacing before the first column and after the last column?
- Highcharts.stockChart Range Selector (zoom) Button Position After the Chart Container
- Why does this Highcharts graph only show tooltip for the first and last nodes?
- Highcharts: Add a button on the chart to hide or show multiple axes
- How to show open, close, high and low in tooltip when the chart type is 'line' in highstocks?
- Getting the tick position and labels for Solid Guage using highcharts
More Query from same tag
- Highcharts drilldown - when useing setData chart doesn't stay drilled down
- HighCharts always throw error #16
- How to create Duplicate DataLabels in highcharts
- How to disable label from Highchart
- Hide linked series on legend hover in Highcharts
- Y-axis on large negative and small positive values in High Charts
- HIghcharts doughnut chart without all the slices
- Highcharts Highstock How to Plot OHLC and Line Charts from One Set of Embedded CSV Data Using Series Map Tools?
- Highcharts not working on Heroku environment, works on local environment
- Is there a way to update a point with Highcharts Boost?
- Removing and re-adding series while keeping the same markers
- Show Fraction values in highchart
- Live HighChart not displaying data
- Issue on Disabling (Not Displaying) Highcharts Drill-up Back Button
- Highcharts not plotting Date string as Category
- Separate threshold for each column
- How to display tooltip data below x-axis category labels using Highcharts
- Click event on highchart axis
- How to fix "Property 'type' is missing in type but required in type 'SeriesXrangeOptions'" in angular highcharts module
- HighCharts wont load in Android webview on Android +4.x
- Highchart (basic line chart) which can have multiple values vs x axis?
- Converting image response, after post request, to file
- legend labelFormatter: getting space between name and percentage so they line up
- Highcharts - is it possible to apply opacity for a specific zone?
- High Charts xAxis first label repeating on all ticks
- Highcharts percent view breaks with multiple series
- Using HighCharts styledMode in Angular 8 application
- Highcharts x series group
- error while installing highcharts in angular app
- highchart not shown data graph