I am trying to use EChart javascript component in the template node of UI Dashboard. The simple test code is as follows. The EChart component does not display in Web UI.
Is the problem due to the usage of ng-style or something else?
1- Load the echarts library. If you are not loading it somewhere in you flow just add a new UI_template node with below config. You need to specify the right path to you static folder in Node-RED where you store the file / library echarts.min.js.
2- Add the missing div element in you ui_template:
<body>
<!-- prepare a DOM container with width and height -->
<div id="divChart" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
var dom = document.getElementById("divChart");
var myChart =null;
myChart = echarts.init(dom);
option = null;
option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line'
}]
};
if (option && typeof option === "object")
{
myChart.setOption(option, true);
}
</script>
</body>
Thanks Andrei.
I tryied again with: style="width: 300px;height:200px;"
then the Echart can be shown for my testing. So, the original problem was related to CSS style.