| <!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" /> | |
| <script src="lib/simpleRequire.js"></script> | |
| <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> | |
| .chart { | |
| width: 260px; | |
| height: 150px; | |
| display: inline-block; | |
| } | |
| </style> | |
| <div id="main"></div> | |
| <script> | |
| require([ | |
| 'echarts' | |
| ], function (echarts) { | |
| var option; | |
| var dataset = [ | |
| ['Group', 'Name', 'Year', 'Value'], | |
| ['A', 'A1', '2020', 10], | |
| ['A', 'A2', '2020', 12], | |
| ['A', 'A3', '2020', 15], | |
| ['A', 'A1', '2021', 8], | |
| ['A', 'A2', '2021', 5], | |
| ['A', 'A3', '2021', 9], | |
| ['B', 'B1', '2020', 5], | |
| ['B', 'B2', '2020', 9], | |
| ['B', 'B3', '2020', 2], | |
| ['B', 'B1', '2021', 15], | |
| ['B', 'B2', '2021', 18], | |
| ['B', 'B3', '2021', 3], | |
| ] | |
| function createOption(groupBy, method) { | |
| return option = { | |
| animation: false, | |
| grid: { | |
| top: 10, | |
| bottom: 20, | |
| containLabel: true, | |
| left: 5, | |
| right: 5 | |
| }, | |
| title: { | |
| text: groupBy + ', ' + method, | |
| left: 'center', | |
| top: 0, | |
| textStyle: { | |
| fontSize: 10 | |
| } | |
| }, | |
| dataset: [ | |
| { | |
| source: dataset | |
| }, | |
| { | |
| fromDatasetIndex: 0, | |
| transform: [{ | |
| type: 'aggregate', | |
| config: { | |
| output: [ | |
| { from: 'Group' }, | |
| { from: 'Name' }, | |
| { from: 'Year' }, | |
| { from: 'Value', method } | |
| ], | |
| groupBy | |
| } | |
| }] | |
| } | |
| ], | |
| xAxis: {type: 'category'}, | |
| yAxis: {}, | |
| series: { | |
| type: 'bar', | |
| datasetIndex: 1, | |
| encode: { | |
| x: groupBy, | |
| y: 'Value', | |
| itemName: groupBy | |
| } | |
| } | |
| }; | |
| } | |
| ['Group', 'Year'].forEach(groupBy => { | |
| ['count', 'sum', 'first', 'min', 'max', 'average', 'Q1', 'Q2', 'Q3', 'median'].forEach(method => { | |
| const dom = document.createElement('div'); | |
| dom.className = 'chart'; | |
| const option = createOption(groupBy, method); | |
| document.querySelector('#main').appendChild(dom); | |
| const chart = echarts.init(dom); | |
| chart.setOption(option); | |
| }); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> | |