I am working on a project. It is a dashboard based on d3.js.
The following problem occurs:
There is the main site (index.html) that contains the navigation menu. I use various dashboards which are inserted into index.html via "object tag".
I looks like this:
<div id="sales1">
<div id="right">
<object id="dashboard1" style="width:900px; height:600px; type="text/html" data="dashboard.html">
</object>
</div>
</div>
Within the dashboard-file (dashboard.html) it is possible to change the datasets (parsed csv) via button:
<!-- here are the buttons to control the two csv data sets -->
<button id="d1">Data 1 (should be units FTP 2018)</button>
<button id="d2">Data 2 (should be units FTP 2019)</button>
<!-- The event listeners for buttons -->
<script>
// here are the event listeners to control the buttons
d3.select("#d1").on("click", function(d, i) {
data1();
});
d3.select("#d2").on("click", function(d, i) {
data2();
});
</script>
Since I want to control this from the navigation menu on the main site (index.html), there must be a way to place buttons and event listeners to the index.html and change datasets within the dashboard from the navigation menu.
So the index.html should look something like this:
Buttons
to change datasets within dashboard.html
<button id="d1">Data 1 (should be units FTP 2018)</button>
<button id="d2">Data 2 (should be units FTP 2019)</button>
Event listeners
to change datasets within dashboard-file(dashboard.html, embedded through object tag)
<script>
?????
</script>
<div id="sales1">
<div id="right">
<object id="dashboard1" style="width:900px; height:600px; type="text/html" data="dashboard.html">
</object>
</div>
</div>
I uploaded the whole code here:
The main site (index.html): https://codepen.io/robx360/pen/wbpoQM Dashboard (dashboard.html): https://codepen.io/robx360/pen/pmpNWN
In the end, there will be various dashboards. By clicking on data 2019, datasets inside the dashboards switch the dataset to 2019 instead of 2018.
objectis suitable for communicating with its external context. In a recent project we wanted to have decoupled navigation and modules; we ended up using iframe inside the navigation page and utilized window messages to bidirectionally interact with the loaded module. Have a look at gist.github.com/pbojinov/8965299