springboot echart
时间: 2023-11-14 15:09:37 浏览: 49
您可以使用 echarts-spring-boot-starter 来在 Spring Boot 中使用 ECharts。该 starter 提供了 ECharts 的自动配置和集成,使得在 Spring Boot 中使用 ECharts 变得更加简单。
您可以通过在 pom.xml 文件中添加以下依赖来使用 echarts-spring-boot-starter:
```xml
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>echarts-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
```
然后,您可以在您的代码中使用 `Echarts` 类来创建图表。例如,以下代码创建了一个简单的柱状图:
```java
import com.github.abel533.echarts.Option;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.series.Bar;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class EchartsController {
@RequestMapping("/echarts")
@ResponseBody
public Option echarts() {
Option option = new Option();
option.title("柱状图");
option.tooltip().trigger("axis");
CategoryAxis categoryAxis = new CategoryAxis();
categoryAxis.data("周一", "周二", "周三", "周四", "周五", "周六", "周日");
option.xAxis(categoryAxis);
option.yAxis(new com.github.abel533.echarts.axis.ValueAxis());
Bar bar = new Bar();
bar.data(120, 200, 150, 80, 70, 110, 130);
option.series(bar);
return option;
}
}
```
在上面的代码中,`Option` 类表示一个 ECharts 图表的配置项。您可以使用 `Option` 类来设置图表的标题、坐标轴、数据系列等。在 `EchartsController` 类中,我们创建了一个简单的柱状图,并将其作为 JSON 格式的响应返回。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)