1. Vega-Lite Bar Chart Example (1)
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 | <!DOCTYPE html> <html> <head> <title>Vega-Lite Bar Chart</title> <meta charset="utf-8" /> <script src="https://cdn.jsdelivr.net/npm/vega@4.4.0/build/vega.js"></script> <script src="https://cdn.jsdelivr.net/npm/vega-lite@3.0.0-rc12/build/vega-lite.js"></script> <script src="https://cdn.jsdelivr.net/npm/vega-embed@3.29.1/build/vega-embed.js"></script> <style media="screen"> /* Add space between Vega-Embed links */ .vega-actions a { margin-right: 5px; } </style> </head> <body> <h1>Template for Embedding Vega-Lite Visualization</h1> <!-- Container for the visualization --> <div id="vis"></div> <script> // Assign the specification to a local variable vlSpec. var vlSpec = { $schema: 'https://vega.github.io/schema/vega-lite/v3.json', data: { values: [ {a: 'C', b: 2}, {a: 'C', b: 7}, {a: 'C', b: 4}, {a: 'D', b: 1}, {a: 'D', b: 2}, {a: 'D', b: 6}, {a: 'E', b: 8}, {a: 'E', b: 4}, {a: 'E', b: 7} ] }, mark: 'bar', encoding: { y: {field: 'a', type: 'nominal'}, x: { aggregate: 'average', field: 'b', type: 'quantitative', axis: { title: 'Average of b' } } } }; // Embed the visualization in the container with id `vis` vegaEmbed('#vis', vlSpec); </script> </body> </html> |
Output:
2. Vega-Lite Bar Chart Example (2)
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 | <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="script/vega.js"></script> <script src="script/vega-lite.js"></script> <script src="script/vega-embed.js"></script> <style media="screen"> /* Add space between Vega-Embed links */ .vega-actions a { margin-right: 5px; } </style> <script> function readSingleFile(e) { var file = e.target.files[0]; if (!file) { return; } var reader = new FileReader(); reader.onload = function(e) { var contents = e.target.result; displayContents(contents); }; reader.readAsText(file); } </script> </head> <body> <div id="vis"></div> <script> var spec = //readSingleFile("vega_demo_2.json"); { "$schema": "https://vega.github.io/schema/vega-lite/v3.json", "description": "A simple bar chart with embedded data.", "width": 360, "data": { "values": [ {"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43}, {"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53}, {"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52} ] }, "mark": "bar", "encoding": { "x": {"field": "a", "type": "ordinal"}, "y": {"field": "b", "type": "quantitative"}, "tooltip": {"field": "b", "type": "quantitative"} } }; vegaEmbed('#vis', spec) </script> </body> </html> |
Output:
3. Vega-Lite Line Chart Example
1 | "mark": "line", |
Output:
4. Vega-Lite Area Chart Example
1 | "mark": "area", |
Output:
댓글 없음:
댓글 쓰기