Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this support the method "dispatchAction" #14

Closed
lyyb2001 opened this issue Mar 16, 2020 · 8 comments
Closed

Does this support the method "dispatchAction" #14

lyyb2001 opened this issue Mar 16, 2020 · 8 comments

Comments

@lyyb2001
Copy link

i have add a method dispatchaction like this
extraScript: '''
chart.dispatchAction({
type:'highlight',
seriesIndex: 1,
dataIndex: 0
});
''',
but this chart is not any display

@entronad
Copy link
Owner

@lyyb2001
If you want to register an action to an event, please try something like:

extraScript: '''
  chart.on('click', (params) => {
    chart.dispatchAction({
      type:'highlight',
      seriesIndex: 1,
      dataIndex: 0
    });
  });
''',

@lyyb2001
Copy link
Author

@lyyb2001
If you want to register an action to an event, please try something like:

extraScript: '''
  chart.on('click', (params) => {
    chart.dispatchAction({
      type:'highlight',
      seriesIndex: 1,
      dataIndex: 0
    });
  });
''',

I mean triggered at initialization, not in response to a user's click event

There are two kinds of events in echarts, one is the mouse event, which will be triggered when clicking a figure, and the other is the event triggered after calling dispatchaction

@entronad
Copy link
Owner

@lyyb2001
The extraScript is executed before any chart.setOption ( I set this order because we don't know when the real setOption happens in async cases.).
I think this is why your dispatchAction didn't work, for in that time the was no option in the chart.
I have a hack idea, you can wrap your dispatchAction in an async function (setTimeout, etc.) to let it execute after your setOption, like:

extraScript: '''
  setTimeout(() => {
    chart.dispatchAction(...);
  }, 0);
''',

@entronad entronad reopened this Mar 20, 2020
@lyyb2001
Copy link
Author

@lyyb2001
The extraScript is executed before any chart.setOption ( I set this order because we don't know when the real setOption happens in async cases.).
I think this is why your dispatchAction didn't work, for in that time the was no option in the chart.
I have a hack idea, you can wrap your dispatchAction in an async function (setTimeout, etc.) to let it execute after your setOption, like:

extraScript: '''
  setTimeout(() => {
    chart.dispatchAction(...);
  }, 0);
''',

Thank you very much for your answer,i tried,but it still doesn't work!
my code is:
final String options = '''
{
animation: false,
grid: {
top: 70,
},
tooltip: {
trigger: 'axis'
},
toolbox: {
show: true
},
legend: {
y: 'bottom',
data:['Normal']
},
xAxis: {
type: 'category',
data: ['3-18','3-19','3-20','3-21','3-22']
},
yAxis: {
type: 'value',
minInterval: 1
},
series: [{
name: 'Normal',
data: [10,20,30,20,10],
type: 'line',
smooth: true,
itemStyle : {
normal : {
color:'#000000',
}
}
},
]
}
''';

Echarts(
option: options,
extraScript: '''
setTimeout(() => {
chart.dispatchAction({
type:'highlight',
seriesIndex: 0,
dataIndex: 0
});
},3000);
''',
)

@entronad
Copy link
Owner

@lyyb2001
Does it work in a web echarts project?

@lyyb2001
Copy link
Author

I'm sorry I made a mistake,Actually, I need to ‘showTip' effect,but i use 'highlight',So without careful observation, the effect is not obvious 。Thank you again for your reply 。This issue can be closed

@entronad
Copy link
Owner

@lyyb2001

By the way, dose it work without the setTimeout or must wrap in the setTimeout?

@sanrixue
Copy link

tooltip 触发方法后 需要 隐藏 但无法隐藏的问题

tooltip 中 自定义 点击操作 触发以下方法

          setTimeout(()=> {
          chart.dispatchAction(
            {
            type: 'hideTip'
          }
          );
            Messager.postMessage(JSON.stringify({
                      params:params,
                }));    
          },3000);

flutter 端可以接收到post过来的数据 但是 tooltip 不可以隐藏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants