初始化
This commit is contained in:
44
.gitignore
vendored
Normal file
44
.gitignore
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Test file
|
||||||
|
test.html
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
.vscode/
|
||||||
|
target/
|
||||||
|
|
||||||
|
.apt_generated/
|
||||||
|
.apt_generated_tests/
|
||||||
|
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
scripts/java
|
||||||
|
scripts/*.ts
|
||||||
|
scripts/*.json
|
||||||
|
/.idea/
|
||||||
172
README.md
Normal file
172
README.md
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
<div align="center">
|
||||||
|
<img src="assets/imgs/logo.png" alt="logo" width=150 height=150 />
|
||||||
|
</div>
|
||||||
|
<h1 align="center">ECharts Java</h1>
|
||||||
|
<p align="center">
|
||||||
|
<em>"We bring better visualization into Java with ECharts"</em>
|
||||||
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/ECharts-Java/ECharts-Java/actions">
|
||||||
|
<img src="https://github.com/ECharts-Java/ECharts-Java/actions/workflows/maven.yml/badge.svg" alt="Github Actions Status">
|
||||||
|
</a>
|
||||||
|
<a href="https://github.com/pyecharts/pyecharts/pulls">
|
||||||
|
<img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat" alt="Contributions welcome">
|
||||||
|
</a>
|
||||||
|
<!-- <a href="https://codecov.io/gh/ECharts-Java/ECharts-Java">
|
||||||
|
<img src="https://codecov.io/gh/ECharts-Java/ECharts-Java/branch/dev/graph/badge.svg?token=V1N6AQ0EA1"/>
|
||||||
|
</a> -->
|
||||||
|
<a href="https://opensource.org/licenses/Apache-2.0">
|
||||||
|
<img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License">
|
||||||
|
</a>
|
||||||
|
<a href="https://maven-badges.herokuapp.com/maven-central/org.icepear.echarts/echarts-java">
|
||||||
|
<img src="https://maven-badges.herokuapp.com/maven-central/org.icepear.echarts/echarts-java/badge.svg" alt="Maven Central">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[中文 README](README.zh.md)
|
||||||
|
|
||||||
|
[Official Documentation](https://echarts.icepear.org/#/)
|
||||||
|
## 📙 Introduction
|
||||||
|
|
||||||
|
ECharts Java is a lightweight but comprehensive library for Java developers to easily use JavaScript visualization library [Apache ECharts](https://echarts.apache.org/en/index.html). The simple chart mode facilitates users to write visualization fast and easily, empowered by the clean APIs provided by ECharts Java. The advanced mode helps create an `Option` object and its Json representation in chainable Java codes, which includes almost all the features defined in [Apache ECharts](https://echarts.apache.org/en/index.html). Now ECharts Java supports Apache ECharts version 5.x.
|
||||||
|
|
||||||
|
## 🌠 Features
|
||||||
|
|
||||||
|
- Simple, clean and organized APIs, supporting method chaining
|
||||||
|
|
||||||
|
- Full coverage of [Apache ECharts](https://echarts.apache.org/en/index.html) functionalities
|
||||||
|
|
||||||
|
- Easily integrate with Web Frameworks
|
||||||
|
|
||||||
|
- Flexible export format, including HTML and images
|
||||||
|
|
||||||
|
- Complete and detailed documentation and examples
|
||||||
|
|
||||||
|
## 🔬 Installation
|
||||||
|
|
||||||
|
For a Maven project, includes the following in your pom.xml
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.icepear.echarts</groupId>
|
||||||
|
<artifactId>echarts-java</artifactId>
|
||||||
|
<version>1.0.7</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
For a Gradle Groovy project, includes
|
||||||
|
```
|
||||||
|
implementation 'org.icepear.echarts:echarts-java:1.0.7'
|
||||||
|
```
|
||||||
|
|
||||||
|
For more, refer to [here](https://search.maven.org/artifact/org.icepear.echarts/echarts-java/1.0.7/jar).
|
||||||
|
|
||||||
|
## 🔭 Usage
|
||||||
|
|
||||||
|
### Generate Local HTML and Download Image
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// All methods in EChart Java supports method chaining
|
||||||
|
Bar bar = new Bar()
|
||||||
|
.setLegend()
|
||||||
|
.setTooltip("item")
|
||||||
|
.addXAxis(new String[] { "Matcha Latte", "Milk Tea", "Cheese Cocoa", "Walnut Brownie" })
|
||||||
|
.addYAxis()
|
||||||
|
.addSeries("2015", new Number[] { 43.3, 83.1, 86.4, 72.4 })
|
||||||
|
.addSeries("2016", new Number[] { 85.8, 73.4, 65.2, 53.9 })
|
||||||
|
.addSeries("2017", new Number[] { 93.7, 55.1, 82.5, 39.1 });
|
||||||
|
Engine engine = new Engine();
|
||||||
|
// The render method will generate our EChart into a HTML file saved locally in the current directory.
|
||||||
|
// The name of the HTML can also be set by the first parameter of the function.
|
||||||
|
engine.render("index.html", bar);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
<img src="assets/imgs/multibar-render.gif" alt="multi-bar-render" style="width:85%;" />
|
||||||
|
|
||||||
|
### Generate Option Object and its JSON Representation
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Line lineChart = new Line()
|
||||||
|
.addXAxis(new CategoryAxis()
|
||||||
|
.setData(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" })
|
||||||
|
.setBoundaryGap(false))
|
||||||
|
.addYAxis()
|
||||||
|
.addSeries(new LineSeries()
|
||||||
|
.setData(new Number[] { 820, 932, 901, 934, 1290, 1330, 1320 })
|
||||||
|
.setAreaStyle(new LineAreaStyle()));
|
||||||
|
Engine engine = new Engine();
|
||||||
|
// It is recommended that you can get the serialized version of Option in the representation of JSON, which can be used directly in the template or in the RESTful APIs.
|
||||||
|
String jsonStr = engine.renderJsonOption(lineChart);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The output JSON object will be like the following,
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"xAxis": [
|
||||||
|
{
|
||||||
|
"type": "category",
|
||||||
|
"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
||||||
|
"boundaryGap": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"yAxis": [{ "type": "value" }],
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"type": "line",
|
||||||
|
"data": [820, 932, 901, 934, 1290, 1330, 1320],
|
||||||
|
"areaStyle": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Integrate with Spring Web Application
|
||||||
|
|
||||||
|
<img src="assets/imgs/line-renderHtml.gif" alt="spring-boot-integration" style="width:75%;" />
|
||||||
|
|
||||||
|
For demo codes, please refer to the [docs](https://echarts.icepear.org/) and [example repo](https://github.com/incandescentxxc/ECharts-Java-Examples).
|
||||||
|
|
||||||
|
## 🎇 Gallery
|
||||||
|
|
||||||
|
<p float="center">
|
||||||
|
<img src="assets/imgs/stacked-line.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/stacked-area.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/multiple-series-bar.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/horizontal-stacked-bar.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-scatter.jpg" width="32%" />
|
||||||
|
<!-- <img src="assets/imgs/basic-boxplot.jpg" width="32%" /> -->
|
||||||
|
<img src="assets/imgs/basic-candlestick.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-heatmap.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-polar-line.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/tangential-polar-bar.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-polar-scatter.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-radar.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-parallel.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-theme-river.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-rose.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/nested-pie.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/circular-layout-graph.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/hide-overlapped-label-graph.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-sankey.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-funnel.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/basic-sunburst.jpg" width="32%" />
|
||||||
|
<img src="assets/imgs/animation-gauge.jpg" width="32%" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## 💡 Authors
|
||||||
|
- [@IcePear-Jzx](https://github.com/IcePear-Jzx)
|
||||||
|
- [@incandescentxxc](https://github.com/incandescentxxc)
|
||||||
|
|
||||||
|
Welcome more contribution in the community!
|
||||||
|
|
||||||
|
## 💌 Acknowledgement
|
||||||
|
- This project is inspired by the Homework 6 of the course [Principles of Software Construction Objects, Design, and Concurrency](https://cmu-17-214.github.io/f2021/), Fall 2021, at [Carnegie Mellon University](https://www.cmu.edu/). We sincerely thank [Christian](https://www.cs.cmu.edu/~ckaestne/) and [Vincent](https://vhellendoorn.github.io/) for the wonderful course.
|
||||||
|
|
||||||
|
- This project is also inspired by the [pyecharts](https://github.com/pyecharts/pyecharts) and [go-echarts](https://github.com/go-echarts/go-echarts), which are the ECharts siblings in Python and Go languages.
|
||||||
|
|
||||||
|
## 🎈 License
|
||||||
|
|
||||||
|
ECharts Java is available under the [Apache License 2.0](LICENSE).
|
||||||
218
pom.xml
Normal file
218
pom.xml
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<artifactId>echarts5-java</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
|
||||||
|
<name>ECharts5 Java</name>
|
||||||
|
<description>
|
||||||
|
基于《echarts-java》基础上进一步丰富
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>nexus-releases</id>
|
||||||
|
<name>Nexus Release Repository</name>
|
||||||
|
<url>http://192.168.1.13:8001/nexus/content/repositories/releases/</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>nexus-snapshots</id>
|
||||||
|
<name>Nexus Snapshot Repository</name>
|
||||||
|
<url>http://192.168.1.13:8001/nexus/content/repositories/snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>njcn</id>
|
||||||
|
<name>hongawen</name>
|
||||||
|
<email>83944980.com</email>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.22</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.jknack</groupId>
|
||||||
|
<artifactId>handlebars</artifactId>
|
||||||
|
<version>4.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>release</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.9.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadocs</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<additionalparam>-Xdoclint:all -Xdoclint:-missing</additionalparam>
|
||||||
|
<!-- <additionalOptions>-Xdoclint:all -Xdoclint:-missing</additionalOptions>-->
|
||||||
|
<additionalJOptions>
|
||||||
|
<additionalJOption>-Xdoclint:all</additionalJOption>
|
||||||
|
<additionalJOption>-Xdoclint:-missing</additionalJOption>
|
||||||
|
</additionalJOptions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<version>1.5</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>sign-artifacts</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
|
<plugins>
|
||||||
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.22</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.puppycrawl.tools</groupId>
|
||||||
|
<artifactId>checkstyle</artifactId>
|
||||||
|
<version>9.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
<configuration>
|
||||||
|
<configLocation>checkstyle.xml</configLocation>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jxr-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
||||||
28
src/main/resources/base.hbs
Normal file
28
src/main/resources/base.hbs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>ECharts Demo</title>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.2.2/echarts.min.js"
|
||||||
|
integrity="sha512-ivdGNkeO+FTZH5ZoVC4gS4ovGSiWc+6v60/hvHkccaMN2BXchfKdvEZtviy5L4xSpF8NPsfS0EVNSGf+EsUdxA=="
|
||||||
|
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<style>
|
||||||
|
#display-container {
|
||||||
|
width: {{width}};
|
||||||
|
height: {{height}};
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="display-container">
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var chart = echarts.init(document.getElementById("display-container"));
|
||||||
|
var option = {{{ option }}}
|
||||||
|
chart.setOption(option);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
70
src/main/resources/index.hbs
Normal file
70
src/main/resources/index.hbs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>ECharts Demo</title>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.2.2/echarts.min.js"
|
||||||
|
integrity="sha512-ivdGNkeO+FTZH5ZoVC4gS4ovGSiWc+6v60/hvHkccaMN2BXchfKdvEZtviy5L4xSpF8NPsfS0EVNSGf+EsUdxA=="
|
||||||
|
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
#title-container {
|
||||||
|
width: {{width}};
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
#download-btn {
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: aliceblue;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
#display-container {
|
||||||
|
width: {{width}};
|
||||||
|
height: {{height}};
|
||||||
|
border: 2px solid black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="container">
|
||||||
|
<div id="title-container">
|
||||||
|
<h1 class="display">ECharts Java</h1>
|
||||||
|
<button id="download-btn" onclick="downloadImage()">Download Image</button>
|
||||||
|
</div>
|
||||||
|
<div id="display-container">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function downloadImage() {
|
||||||
|
let canvas = document.querySelector("canvas");
|
||||||
|
let image = canvas.toDataURL("image/png").replace("image/png",
|
||||||
|
"image/octet-stream");
|
||||||
|
let fakeLink = document.createElement("a");
|
||||||
|
if (typeof fakeLink.download === "string") {
|
||||||
|
document.body.appendChild(fakeLink);
|
||||||
|
fakeLink.download = "echart.png";
|
||||||
|
fakeLink.href = image;
|
||||||
|
fakeLink.click();
|
||||||
|
document.body.removeChild(fakeLink);
|
||||||
|
} else {
|
||||||
|
location.replace(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var chart = echarts.init(document.getElementById("display-container"));
|
||||||
|
var option = {{{ option }}}
|
||||||
|
chart.setOption(option);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user