arashdalir commented on issue #9341: events defined by `chart.on(eventName, 
...` are not triggered
URL: 
https://github.com/apache/incubator-echarts/issues/9341#issuecomment-436598481
 
 
   I'm afraid I have to inform you this **only works to some extension**. 
   now, 
   
   - if _there are no series defiend_, `finished` event is happening **before** 
options are set.
   - if _there is at least one series defined_, the `finished` event is 
**happening** after options are set.
   
   ```javascript
   console.log('started loading');
   
   var myChart = echarts.init(document.getElementById('chart1'), null, {
        "devicePixelRatio": null,
        "renderer": "canvas",
        "width": null,
        "height": "600px"
   });
   
   myChart.on('finished', function (){
        console.log('finished loading');
   });
   
   console.log('setting options');
   myChart.setOption({
        "title": {
                "text": "test",
        },
        "grid": [
                {
                        "top": "5%",
                        "height": "60%",
                        "width": "60%",
                        "left": "5%",
                        "containLabel": false,
                        "borderColor": "transparent",
                        "show": "1"
                }
        ],
        "xAxis": [
                {
                        "type": "category",
                }
        ],
        "yAxis": [
                {
                        "type": "value",
                }
        ],
        //"series": {"name": "insufficient_data", "type": "scatter", 
data:[[0,0]]},
   });
   console.log('options set');
   ```
   ```
   // console output WITHOUT SERIES:
   started loading
   setting options
   finished loading
   options set
   
   // console output WITH series:
   started loading
   setting options
   options set
   finished loading
   ```
   
   > Hmm, it still works for me. But I have set the finished event handler 
before setting the option...:
   > 
   > ```
   > <!doctype HTML5>
   > <html>
   >     <head>
   >    <script src="./echarts-en.min.js"></script>
   >    <script type="text/javascript">
   > 
   > 
   > 
   > function init() {
   >  console.log("init");
   >  
   >  
   > console.log('started loading');
   > 
   > var myChart = echarts.init(document.getElementById('chart1'), null, {
   >    "devicePixelRatio": null,
   >    "renderer": "canvas",
   >    "width": null,
   >    "height": "600px"
   > });
   > myChart.on('finished', function (params){
   >    console.log('finished loading');
   > });
   > myChart.setOption({
   >    "title": {
   >            "text": "test",
   >    },
   >    "grid": [
   >            {
   >                    "top": "5%",
   >                    "height": "60%",
   >                    "width": "60%",
   >                    "left": "5%",
   >                    "containLabel": false,
   >                    "borderColor": "transparent",
   >                    "show": "1"
   >            }
   >    ],
   >    "xAxis": [
   >            {
   >                    "type": "category",
   >                    "min": "dataMin",
   >                    "max": "dataMax"
   >            }
   >    ],
   >    "yAxis": [
   >            {
   >                    "type": "value",
   >            }
   >    ],
   >    // "series": {"name": "insufficient_data", "type": "bar", "data": [[1, 
2], [2, 3]]}, // this works
   >    // "series": {"name": "insufficient_data", "type": "bar", "data": []}, 
// this doesn't work
   >    // "series": {"name": "insufficient_data", "type": "bar"}, // this 
neither
   > });
   > 
   > console.log('options set');
   > 
   >  
   > };
   > 
   > </script>
   >     </head>
   >     <body onload="init()">
   >    <h1>Test</h1>
   >    <div id="chart1" style="width:480px; height:480px"></div>
   > </body>
   > </html>
   > ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to