shop/echarts-master/test/legend-action.html
2025-05-03 23:48:15 +08:00

203 lines
7.2 KiB
HTML
Generated

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8">
<script src="lib/simpleRequire.js"></script>
<script src="lib/config.js"></script>
<script src="lib/testHelper.js"></script>
<link rel="stylesheet" href="./lib/reset.css">
</head>
<body>
<div id="main0"></div>
<div id="main1"></div>
<script>
require([
'echarts'
], function (echarts) {
var option = {
dataset: {
source: [
['type', '2012', '2013', '2014', '2015', '2016'],
['Forest', 320, 332, 301, 334, 390],
['Steppe', 220, 182, 191, 234, 290],
['Desert', 150, 232, 201, 154, 190],
['Wetland', 98, 77, 101, 99, 40]
]
},
legend: [
{
id: 1,
name: 'legend1',
data: ['Steppe', 'Forest'],
left: '10%',
selector: [
{
type: 'all'
},
{
type: 'inverse'
}
]
},
{
id: 2,
name: 'legend2',
data: ['Desert', 'Wetland', 'Steppe' /* test for the same item in other legend */],
right: '10%',
selector: [
{
type: 'all'
},
{
type: 'inverse'
}
]
}
],
xAxis: {
type: 'category'
},
yAxis: {},
series: [
{
type: 'bar',
seriesLayoutBy: 'row'
},
{
type: 'bar',
seriesLayoutBy: 'row'
},
{
type: 'bar',
seriesLayoutBy: 'row'
},
{
type: 'bar',
seriesLayoutBy: 'row'
}
]
};
var chart = window.myChart0 = testHelper.create(echarts, 'main0', {
title: [
'Legend action should be isolated from other legend components\n(except for the items with the same name)'
],
option: option,
buttons: [
{
text: 'Dispatch `legendAllSelect` for both legend components',
onclick() {
chart.dispatchAction({
type: 'legendAllSelect',
legendName: ['legend1', 'legend2'],
// legendId: ['0', '1'],
// legendIndex: [0, 1]
})
}
},
{
text: 'Dispatch `legendInverseSelect` for both legend components',
onclick() {
chart.dispatchAction({
type: 'legendInverseSelect',
// legendName: ['legend1', 'legend2'],
legendId: ['1', '2'],
// legendIndex: [0, 1]
})
}
}
]
});
var logFn = e => console.log(JSON.stringify(e, null, 2));
chart.on('legendselectall', logFn);
chart.on('legendinverseselect', logFn);
chart.on('legendselectchanged', logFn);
});
</script>
<script>
require([
'echarts'
], function (echarts) {
var option = {
dataset: {
source: [
['type', '2012', '2013', '2014', '2015', '2016'],
['Forest', 320, 332, 301, 334, 390],
['Steppe', 220, 182, 191, 234, 290],
['Desert', 150, 232, 201, 154, 190],
['Wetland', 98, 77, 101, 99, 40]
]
},
legend: [
{
id: 1,
name: 'legend1',
data: ['Steppe', 'Forest'],
left: '10%',
triggerEvent: true
},
{
id: 2,
name: 'legend2',
data: ['Desert', 'Wetland', 'Steppe' /* test for the same item in other legend */],
right: '10%',
triggerEvent: true
}
],
xAxis: {
type: 'category'
},
yAxis: {},
series: [
{
type: 'bar',
seriesLayoutBy: 'row'
},
{
type: 'bar',
seriesLayoutBy: 'row'
},
{
type: 'bar',
seriesLayoutBy: 'row'
},
{
type: 'bar',
seriesLayoutBy: 'row'
}
]
};
var chart = window.myChart0 = testHelper.create(echarts, 'main1', {
title: [
'Legend triggerEvent(hover legend item to see the log)'
],
option: option
});
var logFn = e => {if(e.componentType === 'legend') console.log(e)};
chart.on('mouseover', logFn);
chart.on('mouseout', logFn);
});
</script>
</body>
</html>