axes.html 14.2 KB
Newer Older
P
pah100 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
<html>
    <head>
        <meta charset="utf-8">
        <script src="esl.js"></script>
        <script src="config.js"></script>
        <link rel="stylesheet" href="reset.css">
    </head>
    <body>
        <style>
            #main {
                position: relative;
                min-width: 1080px; /* 4 columns */
            }
            .title {
                clear: both;
                text-align: center;
                margin: 0;
                background: #eef;
            }
            .block {
                float: left;
                margin: 30px 0 30px 50px;
            }
            .block .ec {
                width: 200px;
                height: 200px;
            }
            .block label {
                width: 200px;
                display: block;
                text-align: center;
                background: #eee;
                border-radius: 3px;
                font-size: 12px;
                line-height: 18px;
                padding: 0 5px;
            }
        </style>

        <div id="main"></div>

        <script>

            var echarts;
            var zrUtil;

            require([
                'echarts',
                'zrender/core/util',
                'echarts/chart/line',
                'echarts/chart/parallel',
                'echarts/component/legend',
                'echarts/component/grid',
                'echarts/component/polar',
                'echarts/component/parallel',
                'echarts/component/tooltip'
            ], function (ec, zu) {
                echarts = ec;
                zrUtil = zu;

                var makeCartesian = zrUtil.curry(makeChart, defaultCartesianOption);

                renderTitle('catesian normal');

                // inverse
                makeCartesian('x: forward, y: forward', {
                    xAxis: {},
                    yAxis: {}
                });
                makeCartesian('x: inverse, y: inverse', {
                    xAxis: {inverse: true},
                    yAxis: {inverse: true}
                });
                makeCartesian('x: forward, y: inverse', {
                    xAxis: {},
                    yAxis: {inverse: true}
                });
                makeCartesian('x: inverse, y: forward', {
                    xAxis: {inverse: true},
                    yAxis: {}
                });

                renderTitle('catesian position setting');

                // position
                makeCartesian('x: forward top, y: forward right', {
                    xAxis: {position: 'top'},
                    yAxis: {position: 'right'}
                });
                makeCartesian('x: inverse bottom, y: inverse right', {
                    xAxis: {inverse: true, position: 'bottom'},
                    yAxis: {inverse: true, position: 'right'}
                });
                makeCartesian('x: forward bottom, y: inverse right', {
                    xAxis: {position: 'bottom'},
                    yAxis: {inverse: true, position: 'right'}
                });
                makeCartesian('x: inverse top, y: forward right', {
                    xAxis: {inverse: true, position: 'top'},
                    yAxis: {position: 'right'}
                });

                renderTitle('catesian name location');

                // name location
                makeCartesian('x: forward start, y: forward start', {
                    xAxis: {nameLocation: 'start'},
                    yAxis: {nameLocation: 'start'}
                });
                makeCartesian('x: inverse start, y: inverse start', {
                    xAxis: {inverse: true, nameLocation: 'start'},
                    yAxis: {inverse: true, nameLocation: 'start'}
                });
                makeCartesian('x: forward start, y: inverse start', {
                    xAxis: {nameLocation: 'start'},
                    yAxis: {inverse: true, nameLocation: 'start'}
                });
                makeCartesian('x: inverse start, y: forward start', {
                    xAxis: {inverse: true, nameLocation: 'start'},
                    yAxis: {nameLocation: 'start'}
                });

                renderTitle('polar normal');

                var makePolar = zrUtil.curry(makeChart, defaultPolarOption);

                // inverse
                makePolar('angle: forward, radius: forward', {
                    angleAxis: {},
                    radiusAxis: {}
                });
                makePolar('angle: inverse, radius: inverse', {
                    angleAxis: {inverse: true},
                    radiusAxis: {inverse: true}
                });
                makePolar('angle: forward, radius: inverse', {
                    angleAxis: {},
                    radiusAxis: {inverse: true}
                });
                makePolar('angle: inverse, radius: forward', {
                    angleAxis: {inverse: true},
                    radiusAxis: {}
                });

                renderTitle('polar angle settting');

                // startAngle
                makePolar('angle: forward startAngle23, radius: forward', {
                    angleAxis: {startAngle: 23},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle64, radius: forward', {
                    angleAxis: {startAngle: 64},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle90, radius: forward', {
                    angleAxis: {startAngle: 90},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle108, radius: forward', {
                    angleAxis: {startAngle: 108},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle164, radius: forward', {
                    angleAxis: {startAngle: 164},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle180, radius: forward', {
                    angleAxis: {startAngle: 180},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle204, radius: forward', {
                    angleAxis: {startAngle: 204},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle250, radius: forward', {
                    angleAxis: {startAngle: 250},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle270, radius: forward', {
                    angleAxis: {startAngle: 270},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle270, radius: forward', {
                    angleAxis: {startAngle: 270},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle294, radius: forward', {
                    angleAxis: {startAngle: 294},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle344, radius: forward', {
                    angleAxis: {startAngle: 344},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle360, radius: forward', {
                    angleAxis: {startAngle: 360},
                    radiusAxis: {}
                });

                renderTitle('polar inverse angle settting');

                // startAngle
                makePolar('angle: inverse startAngle23, radius: forward', {
                    angleAxis: {inverse: true, startAngle: 23},
                    radiusAxis: {}
                });
                makePolar('angle: forward startAngle23, radius: inverse', {
                    angleAxis: {startAngle: 23},
                    radiusAxis: {inverse: true}
                });

                renderTitle('parallel');

                var makeParallel = zrUtil.curry(makeChart, defaultParallelOption);

                makeParallel('layout: horizontal', {
                });
                makeParallel('layout: horizontal, axis2 forward start', {
                    parallelAxis: makeParallelAxisOption({nameLocation: 'start'})
                });
                makeParallel('layout: horizontal, axis2 inverse start', {
                    parallelAxis: makeParallelAxisOption({inverse: true, nameLocation: 'start'})
                });
                makeParallel('layout: vertical', {
                });
                makeParallel('layout: vertical, axis2 forward start', {
                    parallel: {layout: 'vertical'},
                    parallelAxis: makeParallelAxisOption({nameLocation: 'start'})
                });
                makeParallel('layout: vertical, axis2 inverse start', {
                    parallel: {layout: 'vertical'},
                    parallelAxis: makeParallelAxisOption({inverse: true, nameLocation: 'start'})
                });

            });

            function makeParallelAxisOption(secondOpt) {
                return [
P
pah100 已提交
240
                    {dim: 0, name: '维度1'},
P
pah100 已提交
241
                    zrUtil.merge({dim: 'dim1', name: '维度2'}, secondOpt, true),
P
pah100 已提交
242 243
                    {dim: 2, name: '维度3'},
                    {dim: 3, name: '维度4'}
P
pah100 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
                ];
            }

            function renderTitle(label) {
                var containerEl = document.getElementById('main');
                var el = document.createElement('div');
                el.className = 'title';
                el.innerHTML = encodeHTML(label);
                containerEl.appendChild(el);
            }


            function makeChart(getOption, label, opt) {
                opt = opt || {};
                var containerEl = document.getElementById('main');
                var el = document.createElement('div');
                el.className = 'block';
                el.innerHTML = '<div class="ec"></div><label>' + encodeHTML(label) + '</label>';
                containerEl.appendChild(el);

                var chart = echarts.init(el.firstChild, null, {renderer: 'canvas'});
                chart.setOption(zrUtil.merge(opt, getOption()));
            }

            function defaultCartesianOption() {

                var xAxisData = [];
                var data1 = [];

                for (var i = 0; i < 30; i++) {
                    xAxisData.push('类目' + i);
                    data1.push(+(Math.random() + 0.5).toFixed(3));
                }

                return {
                    legend: {
                        data: ['line', 'line2', 'line3']
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {type: 'line'}
                    },
                    grid: {x: 50, y: 50, x2: 50, y2: 50},
                    xAxis: {
                        data: xAxisData,
                        name: 'XName',
                        boundaryGap: false,
                        splitArea: {show: false},
                        splitLine: {show: false}
                    },
                    yAxis: {
                        name: 'YName',
                        splitArea: {show: true}
                    },
                    series: [{
                        name: 'line',
                        type: 'line',
                        stack: 'all',
                        symbol: 'circle',
                        symbolSize: 10,
                        data: data1,
                        itemStyle: {
                            normal: {
                                borderColor: 'white',
                                borderWidth: 3,
                                lineStyle: {width: 1}
                            }
                        }
                    }]
                };
            }

            function defaultPolarOption() {

                var xAxisData = [];
                var data1 = [];

                for (var i = 0; i < 8; i++) {
                    xAxisData.push('类目' + i);
                    data1.push((Math.random() * 2 + 1).toFixed(3));
                }

                return {
                    legend: {
                        data: ['line', 'line2', 'line3']
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {type: 'shadow'}
                    },
                    polar: {radius: '65%'},
                    angleAxis: {data: xAxisData},
                    radiusAxis: {splitNumber: 4},
                    series: [{
                        coordinateSystem: 'polar',
                        name: 'line',
                        stack: 'all',
                        type: 'line',
                        symbolSize: 10,
                        itemStyle: {normal: {areaStyle: {}}},
                        data: data1
                    }]
                };
            }

            function defaultParallelOption() {

                var dataBJ = [];
                for (var i = 0; i < 10; i++) {
                    var item = [];
                    for (var j = 0; j < 4; j++) {
                        item.push(Math.random() * 10);
                    }
                    dataBJ.push(item);
                }

                return {
                    color: [
                        '#dd4444', '#fec42c', '#80F1BE'
                    ],
                    parallelAxis: makeParallelAxisOption(),
                    parallel: {
                        x: 40,
                        y: 40,
                        x2: 40,
                        y2: 40,
                        parallelAxisDefault: {
                            type: 'value'
                        }
                    },
                    series: [
                        {
                            name: '北京',
                            type: 'parallel',
                            data: dataBJ
                        }
                    ]
                };
            }

            function encodeHTML(source) {
                return source == null
                    ? ''
                    : String(source)
                        .replace(/&/g, '&amp;')
                        .replace(/</g, '&lt;')
                        .replace(/>/g, '&gt;')
                        .replace(/"/g, '&quot;')
                        .replace(/'/g, '&#39;');
            };

        </script>
    </body>
</html>