legend-style.html 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<!DOCTYPE html>
<!--
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">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
P
pissang 已提交
24
        <script src="lib/simpleRequire.js"></script>
25 26 27 28 29 30 31 32 33 34 35 36 37
        <script src="lib/config.js"></script>
        <script src="lib/jquery.min.js"></script>
        <script src="lib/facePrint.js"></script>
        <script src="lib/testHelper.js"></script>
        <!-- <script src="ut/lib/canteen.js"></script> -->
        <link rel="stylesheet" href="lib/reset.css" />
    </head>
    <body>
        <style>
        </style>


        <div id="main1"></div>
O
Ovilia 已提交
38
        <div id="main2"></div>
C
ChepteaCatalin 已提交
39
        <div id="main3"></div>
40 41

        <script>
O
Ovilia 已提交
42
            function getData(seriesId) {
43 44 45 46 47
                var data = [];
                for (var i = 0; i < 7; ++i) {
                    data.push(Math.random() * 100 + (seriesId + 1) * 200);
                }
                return data;
O
Ovilia 已提交
48 49
            }
        </script>
50

O
Ovilia 已提交
51 52
        <script>
        require(['echarts'], function (echarts) {
53 54 55 56 57 58 59 60
            var option = {
                xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                },
                yAxis: {
                    type: 'value'
                },
O
Ovilia 已提交
61 62 63 64
                legend: [{
                    data: [
                        'Line A',
                        'Line B',
O
Ovilia 已提交
65 66 67 68 69 70 71 72 73 74
                        {
                            name: 'Line C',
                            symbolSize: 'inherit'
                        },
                        'Line F',
                        'Pie A',
                        'Pie B',
                        'Pie C',
                        'Pie D'
                    ]
O
Ovilia 已提交
75 76 77
                }, {
                    bottom: 10,
                    data: [{
O
Ovilia 已提交
78
                        name: 'Line D',
79
                        icon: 'arrow'
O
Ovilia 已提交
80 81 82
                    }, {
                        name: 'Line E',
                        itemStyle: {
O
Ovilia 已提交
83
                            color: '#f0f'
O
Ovilia 已提交
84 85 86 87
                        }
                    }],
                    itemStyle: {
                        color: 'orange'
O
Ovilia 已提交
88 89
                    },
                    icon: 'emptyRect'
O
Ovilia 已提交
90
                }],
91 92 93
                series: [{
                    data: getData(0),
                    type: 'line',
O
Ovilia 已提交
94
                    name: 'Line A'
95 96 97
                }, {
                    data: getData(1),
                    type: 'line',
O
Ovilia 已提交
98 99 100 101 102
                    name: 'Line B',
                    itemStyle: {
                        color: 'red',
                        borderWidth: 5
                    },
O
Ovilia 已提交
103
                    symbolSize: 15,
104 105
                    symbol: 'emptyTriangle',
                    symbolRotate: 15
106 107 108
                }, {
                    data: getData(2),
                    type: 'line',
O
Ovilia 已提交
109 110 111 112 113 114 115
                    name: 'Line C',
                    lineStyle: {
                        color: 'green',
                        width: 5,
                        shadowBlur: 10,
                        shadowColor: 'orange'
                    },
116
                    itemStyle: {
O
Ovilia 已提交
117 118 119
                        color: 'red'
                    },
                    symbolSize: 30
120 121 122
                }, {
                    data: getData(3),
                    type: 'line',
O
Ovilia 已提交
123
                    name: 'Line D',
124
                    itemStyle: {
O
Ovilia 已提交
125
                        color: 'blue'
O
Ovilia 已提交
126 127 128
                    },
                    symbol: 'emptyTriangle',
                    symbolSize: 15
129 130 131
                }, {
                    data: getData(4),
                    type: 'line',
O
Ovilia 已提交
132 133 134 135 136 137 138 139 140 141
                    name: 'Line E',
                    itemStyle: {
                        color: 'green'
                    },
                    symbolSize: 10
                }, {
                    data: getData(5),
                    type: 'line',
                    name: 'Line F',
                    symbolSize: 10,
142
                    itemStyle: {
O
Ovilia 已提交
143
                        color: 'blue'
144 145 146 147 148 149 150 151
                    }
                }, {
                    type: 'pie',
                    data: [{
                        name: 'Pie A',
                        value: 10
                    }, {
                        name: 'Pie B',
O
Ovilia 已提交
152 153 154 155
                        value: 8,
                        itemStyle: {
                            borderWidth: 0
                        }
156 157 158 159
                    }, {
                        name: 'Pie C',
                        value: 14,
                        itemStyle: {
O
Ovilia 已提交
160 161
                            color: 'blue',
                            borderColor: 'green'
162
                        }
O
Ovilia 已提交
163 164 165
                    }, {
                        name: 'Pie D',
                        value: 2
166
                    }],
O
Ovilia 已提交
167
                    itemStyle: {
O
Ovilia 已提交
168
                        borderWidth: 10,
O
Ovilia 已提交
169 170
                        borderColor: '#fff'
                    },
O
Ovilia 已提交
171 172
                    center: ['80%', '50%'],
                    radius: '40%'
173 174 175 176 177
                }],
                grid: {
                    left: 60,
                    width: '55%'
                },
O
Ovilia 已提交
178
                visualMap: [{
179
                    type: 'continuous',
O
Ovilia 已提交
180 181
                    min: 1200,
                    max: 1300,
182 183 184 185
                    inRange: {
                        color: ['green', 'yellow', 'red']
                    },
                    show: false,
O
Ovilia 已提交
186
                    seriesIndex: 5
O
Ovilia 已提交
187 188 189 190 191 192 193 194 195 196
                }, {
                    type: 'continuous',
                    min: 5,
                    max: 15,
                    inRange: {
                        color: ['green', 'yellow', 'red']
                    },
                    show: false,
                    seriesIndex: 6
                }],
O
Ovilia 已提交
197
                animation: 0
198 199 200 201
            };

            var chart = testHelper.create(echarts, 'main1', {
                title: [
O
Ovilia 已提交
202 203 204 205
                    '**Legend icon being more intuitive**',
                    'Line A: the style of the line and items should be the same in those in legend; all colored in the first theme color',
                    'Line B: the style of the line and items should be the same in those in legend; all colored in red',
                    'Line C: the style of the line and items should be the same in those in legend; items colored in red and line colored in green',
206 207
                    'Line D: orange arrow in legend and blue empty triangle in series',
                    'Line E: pink empty rectangale in legend and green empty circle in series',
O
Ovilia 已提交
208
                    'Line F: the colors in the legend should be blue'
209 210 211 212 213 214 215
                ],
                option: option
            });
        });
        </script>


216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
        <script>
        require(['echarts'], function (echarts) {
            var option = {
                xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                },
                yAxis: {
                    type: 'value'
                },
                legend: [{
                    data: [
                        'Line A',
                        'Line B',
                        {
                            name: 'Line C',
                            symbolRotate: -30,
                            icon: 'emptyTriangle'
234 235
                        },
                        'Bar D'
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
                    ],
                    symbolRotate: 30,
                    itemWidth: 100
                }],
                series: [{
                    data: getData(0),
                    type: 'line',
                    name: 'Line A',
                    symbol: 'emptyRect'
                }, {
                    data: getData(1),
                    type: 'line',
                    name: 'Line B',
                    symbol: 'emptyTriangle',
                    symbolRotate: 15,
                    symbolSize: 10,
                    symbolKeepAspect: true
                }, {
                    data: getData(2),
                    type: 'line',
                    name: 'Line C',
                    symbol: 'emptyTriangle',
                    symbolKeepAspect: true
259 260 261 262
                }, {
                    data: getData(0),
                    type: 'bar',
                    name: 'Bar D'
263 264 265 266 267 268 269 270 271
                }],
                animation: 0
            };

            var chart = testHelper.create(echarts, 'main2', {
                title: [
                    '**Legend options should work**',
                    'Line A: the rect in the legend should be placed at the center with rotation of 30 degrees',
                    'Line B: the triangle in the legend should be placed at the center with rotation of 30 degrees',
272 273
                    'Line C: should not have rotate in legend',
                    'Bar D: should not have rotate in legend'
274 275 276 277 278
                ],
                option: option
            });
        });
        </script>
C
ChepteaCatalin 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333


    <script>
        require(['echarts'], function (echarts) {
            var option = {
                textStyle: {
                    color: 'green'
                },
                legend: {
                    data: ['Line A', 'Line B'],
                    inactiveColor: 'gray',
                    selected: { 'Line A': false, 'Line B': true },
                    textStyle: {
                        color: 'red',
                        rich: {
                            bold: {
                                color: 'inherit',
                            },
                        },
                    },
                    formatter: function (name) {
                        return `{bold|${name}}`
                    }
                },
                xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: 'Line A',
                        type: 'line',
                        data: [69, 50],
                    },
                    {
                        name: 'Line B',
                        type: 'line',
                        data: [120, 130]
                    },
                ]
            };

            var chart = testHelper.create(echarts, 'main3', {
                title: [
                    '**Legend rich text should inherit color from legend option**',
                    'Line A: gray text',
                    'Line B: red text',
                ],
                option: option
            });
        });
    </script>
334 335
    </body>
</html>