问题描述
通过在Eclipse / STS中使用Spring Stater Project,我能够快速启动并运行Vaadin项目。我想通过Vaadin-Addon将图表添加到项目中。我谷歌搜索试图找到如何正确添加和使用Vaadin Chart插件到项目。但我很困惑,因为有很多指南/教程,但很多不是春季启动或他们已经过时或部分。
所以我正在寻找Vaadin-SpringBoot-VaadinChart-AddOn的完整指南/教程。
这个是我到目前为止:
---- Pom文件----
<?xml version =1.0encoding =UTF-8?>
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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.aci< / groupId>
< artifactId> oversight2< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< packaging> jar< / packaging>
< name> oversight2< / name>
< description> Oversite< / description>
< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.2.5.RELEASE< / version>
< relativePath /> <! - 从存储库查找父级 - >
< / parent>
< properties>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< java.version> 1.8< /java.version>
< / properties>
< dependencies>
<! - < dependency> - >
<! - < groupId> com.vaadin< / groupId> - >
<! - < artifactId> vaadin-spring-boot< / artifactId> - >
<! - < version> 1.0.0< / version> - >
<! - < / dependency> - >
<依赖>
< groupId> com.vaadin< / groupId>
< artifactId> vaadin-spring-boot-starter< / artifactId>
< version> 1.0.0.beta3< / version>
< / dependency>
<依赖>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-test< / artifactId>
< scope> test< / scope>
< / dependency>
< dependency>
< groupId> com.vaadin.addon< / groupId>
< version> 2.0.0< / version>
< artifactId> vaadin-charts< / artifactId>
< / dependency>
< / dependencies>
< dependencyManagement>
< dependencies>
< dependency>
< groupId> com.vaadin< / groupId>
< artifactId> vaadin-bom< / artifactId>
< version> 7.4.5< / version>
< type> pom< / type>
< scope> import< / scope>
< / dependency>
< / dependencies>
< / dependencyManagement>
< build>
< plugins>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
< / plugin>
< / plugins>
< / build>
< repositories>
< repository>
< id> vaadin-addons< / id>
< url> http://maven.vaadin.com/vaadin-addons< / url>
< / repository>
< / repositories>
< / project>
---- Java代码----
public class BasicBarChart extends AbstractVaadinChartExample {
@Override
public String getDescription(){
返回基本栏;
}
@Override
protected组件getChart(){
图表图表=新图表(ChartType.BAR);
配置conf = chart.getConfiguration();
conf.setTitle(各地区历史世界人口);
conf.setSubTitle(来源:Wikipedia.org);
XAxis x = new XAxis();
x.setCategories(非洲,美国,亚洲,欧洲,大洋洲);
x.setTitle((String)null);
conf.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
标题title =新标题(人口(百万));
title.setVerticalAlign(VerticalAlign.HIGH);
y.setTitle(title);
conf.addyAxis(y);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter(this.series.name +':'+ this.y +'million');
conf.setTooltip(tooltip);
PlotOptionsBar plot = new PlotOptionsBar();
plot.setDataLabels(new Labels(true));
conf.setPlotOptions(plot);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setHorizontalAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-100);
legend.setY(100);
legend.setFloating(true);
legend.setBorderWidth(1);
legend.setBackgroundColor(#FFFFFF);
legend.setShadow(true);
conf.setLegend(legend);
conf.disableCredits();
List series = new ArrayList();
series.add(new ListSeries(Year 1800,107,31,635,203,2));
series.add(new ListSeries(Year 1900,133,156,947,408,6));
series.add(new ListSeries(Year 2008,973,914,4054,732,34));
conf.setSeries(系列);
chart.drawChart(conf);
返回图表;
}
}
@SpringUI
@VaadinServletConfiguration(productionMode = false,ui = MyVaadinUI.class)
公共类MyVaadinUI扩展UI {
@Override
protected void init(VaadinRequest vaadinRequest){
setContent(new BasicBarChart());
}
}
我已经创建了30天的AGPL许可证密钥
有些网站说我需要一个gwt.xml文件,或者这可以通过注释完成
一些网站说我需要重新编译你的widgetset,这意味着我需要在我的pom文件中添加一些插件。
其他网站说我需要一个web.xml,但只需运行spring-boot-vaadin Vaadin应用程序。
该过程与所有加载项相同。对于简单的应用程序,您只需要核心小部件,并可以使用DefaultWidgetSet。你需要在项目中加入ApplicationWidgetset,它将核心的基本客户端组件实现与你在项目中使用的所有附加组件结合起来。
这些是使用TouchKit附加组件的示例说明,但过程基本相同:
- 使用cdn.virit.in的简单选项:
- 将插件添加到
- 将生成的servlet过滤器添加到配置
- 标准解决方案:
- 添加
- 将@Widgetset注释添加到
By using "Spring Stater Project" in Eclipse/STS, I was able to have a Vaadin project up and running quickly. I want to add charting via Vaadin-Addon to the project. I have Googled trying to find how to properly add and use Vaadin Chart addon to the project. But I am confused because there so many "Guides/Tutorial", but a lot are not for spring boot or they are outdated or partial.
So I am looking for a complete Guide/Tutorial for Vaadin-SpringBoot-VaadinChart-AddOn.
This is what I have so far:
---- Pom file ----
<?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.aci</groupId>
<artifactId>oversight2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>oversight2</name>
<description>Oversite</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>com.vaadin</groupId> -->
<!-- <artifactId>vaadin-spring-boot</artifactId> -->
<!-- <version>1.0.0</version> -->
<!-- </dependency> -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.0.0.beta3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin.addon</groupId>
<version>2.0.0</version>
<artifactId>vaadin-charts</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>7.4.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
</project>
---- Java code ----
public class BasicBarChart extends AbstractVaadinChartExample {
@Override
public String getDescription() {
return "Basic bar";
}
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.BAR);
Configuration conf = chart.getConfiguration();
conf.setTitle("Historic World Population by Region");
conf.setSubTitle("Source: Wikipedia.org");
XAxis x = new XAxis();
x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
x.setTitle((String) null);
conf.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
Title title = new Title("Population (millions)");
title.setVerticalAlign(VerticalAlign.HIGH);
y.setTitle(title);
conf.addyAxis(y);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
conf.setTooltip(tooltip);
PlotOptionsBar plot = new PlotOptionsBar();
plot.setDataLabels(new Labels(true));
conf.setPlotOptions(plot);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setHorizontalAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-100);
legend.setY(100);
legend.setFloating(true);
legend.setBorderWidth(1);
legend.setBackgroundColor("#FFFFFF");
legend.setShadow(true);
conf.setLegend(legend);
conf.disableCredits();
List series = new ArrayList();
series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
conf.setSeries(series);
chart.drawChart(conf);
return chart;
}
}
@SpringUI
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class)
public class MyVaadinUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
setContent(new BasicBarChart());
}
}
I have create a 30 day AGPL license key
There are some sites that say I need a gwt.xml file, or can this be done with annotations
Some sites say I need to "re-compile your widgetset" which implies I need to have some plugin addition to my pom file.
Other sites say I need a web.xml but with spring-boot-vaadin Vaadin app with just run.
When I run the code, I am getting :
The process is the same as with all add-ons. For simple apps you only need core widgets and can use the "DefaultWidgetSet". You'll need to have "ApplicationWidgetset" with your project that combines basic client side component implementations from the core with all the add-ons that you use in your project.
These are instructions from example using TouchKit add-on, but the process is basically the same:
- Simple option using cdn.virit.in:
- Add plugin to pom.xml
- Add generated servlet filter to your configuration https://github.com/mstahv/vaadin-spring-touchkit/blob/master/src/main/java/org/vaadin/tkspring/Application.java#L20-L25
- Standard solution:
- Add vaadin-maven-plugn to pom.xml
- Add @Widgetset annotation to your UI class
这篇关于我如何修复'com.vaadin.DefaultWidgetSet'不包含com.vaadin.addon.charts.Chart的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!