how to do charts using vaadin charts?

Hello,

I am a beginner and trying to learn vaadin Add ons. I started from vaadin charts. I have tried to re-do the chart from webinar https://www.youtube.com/watch?v=coxGUOxANLg.

This means that I have the following code The code has no error at all. I am using tomacat v7. I drag and drop the jar-file (vaadin-charts-1.1.5.jar) into lib directory. I added json library.

However, I still have the following problem while trying to run the project… (see it after the code below )

I really would apprciate it if one can address my problem.

Many many thanks in advance.

package com.example.myproject;

import javax.servlet.annotation.WebServlet;

import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.model.Configuration;
import com.vaadin.addon.charts.model.ListSeries;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings(“serial”)
@Theme(“myproject”)
public class MyprojectUI extends UI {

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyprojectUI.class, widgetset = "com.example.myproject.widgetset.MyprojectWidgetset")
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);

    Button button = new Button("Click Me");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
        }
    });
    layout.addComponent(button);
    
    Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    
    ListSeries listseries = new ListSeries(2,3,4,5);
    configuration.addSeries(listseries);
    
    layout.addComponent(chart);
    
    
    
}

}

[color=#FF0000]
HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory

type Exception report

message com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory

description The server encountered an internal error that prevented it from fulfilling this request.

exceptionjavax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory com.vaadin.server.VaadinServlet.service(VaadinServlet.java:240) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)root causecom.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1445) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1399) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)root causejava.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory com.vaadin.addon.charts.Chart.(Chart.java:137) com.example.myproject.MyprojectUI.init(MyprojectUI.java:41) com.vaadin.ui.UI.doInit(UI.java:625) com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223) com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73) com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1387) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)root causejava.lang.ClassNotFoundException: com.google.gson.TypeAdapterFactory org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) com.vaadin.addon.charts.Chart.(Chart.java:137) com.example.myproject.MyprojectUI.init(MyprojectUI.java:41) com.vaadin.ui.UI.doInit(UI.java:625) com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223) com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73) com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1387) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

Apache Tomcat/7.0.47
[/color]

Do you use Maven or Ivy or any other kind of dependency management framework for your project? If not, please make sure you have all the jar files from the vaadin-charts zip lib folder on the classpath for the project. There’s also the gson-2.2.jar which need to be found.

// Jonas

Hi Jonas,

Thanks for your response. I have already solved.

//Michael

Dear All,

After I did using Jonas’ answer. The log shows vaadin charts’s license. Like this


LICENSE WARNING

Vaadin Charts is a commercial product. After 30 days of evaluation use,
you must either acquire a license or stop using it. More information about
Commercial Vaadin Add-on License is available at
https://vaadin.com/license/cval-2.0.

You may obtain a valid license by subscribing to Vaadin Pro Account at
https://vaadin.com/pro or by purchasing a perpetual license at
https://vaadin.com/directory.

A valid license key is your perpetual license key purchased from Vaadin
Directory or alternatively the email address you use to login to an active
Vaadin Pro Account.

Register your copy of Vaadin Charts by creating a file named
.vaadin.charts.developer.license containing the license key in your home
directory or by setting the vaadin.charts.developer.license=license_key
system property to disable this message. Thank you.

How shoud I do next
Thank you

You can check the instructions at
https://vaadin.com/directory/help/installing-cval-license
for details on how to sort out the license warning.

How did you resolve it?