Highcharts Dashboards demo
by stitot
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/dashboards/dashboards.js"></script>
<script src="https://code.highcharts.com/dashboards/modules/layout.js"></script>
<div id="container"></div>
CSS
@import url("https://code.highcharts.com/dashboards/css/datagrid.css");
@import url("https://code.highcharts.com/dashboards/css/dashboards.css");
iframe {
width: 100%;
height: 100%;
}
.highcharts-dashboards-cell {
padding: 10px;
}
@media screen and (max-width: 576px) {
.highcharts-dashboards-cell {
flex: 1 1 100%;
}
}
JavaScript
const { ComponentRegistry, Component } = Dashboards;
class YouTubeComponent extends Component {
constructor(cell, options) {
super(cell, options);
this.type = 'YouTube';
this.youTubeElement = document.createElement('iframe');
this.options.editableOptions = [{
name: 'videoId',
propertyPath: ['videoId'],
type: 'input'
}, {
name: 'title',
propertyPath: ['title'],
type: 'input'
}, {
name: 'caption',
propertyPath: ['caption'],
type: 'input'
}];
return this;
}
async load() {
super.load();
this.youTubeElement.setAttribute(
'src',
'https://www.youtube.com/embed/' + this.options.videoId
);
this.youTubeElement.setAttribute('title', 'YouTube video player');
this.youTubeElement.setAttribute('frameborder', '0');
this.youTubeElement.allowfullscreen = true;
this.contentElement.appendChild(this.youTubeElement);
this.parentElement.appendChild(this.element);
return this;
}
async update(newOptions, shouldRerender) {
super.update.call(this, newOptions, shouldRerender);
this.youTubeElement.setAttribute(
'src',
'https://www.youtube.com/embed/' + this.options.videoId
);
this.cell.setLoadingState(false);
}
getOptionsOnDrop(sidebar) {
super.getOptionsOnDrop.call(this, sidebar);
return {
renderTo: '',
type: 'YouTube',
videoId: '115hdz9NsrY'
};
}
}
ComponentRegistry.registerComponent('YouTube', YouTubeComponent);
Dashboards.board('container', {
editMode: {
enabled: true,
lang: {
videoId: 'Video ID',
sidebar: {
YouTube: 'YouTube'
}
},
contextMenu: {
enabled: true
...