Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Vaadin Charts

series.setNamePropertyId("name");

series.setYPropertyId("diameter");

conf.addSeries(series);

As the X axis holds categories rather than numeric values, we need to set up the category labels with an array of string. There are a few ways to do that, some more efficient than others, below is one way:

// Set the category labels on the axis correspondingly XAxis xaxis = new XAxis();

String names[] = new String[container.size()]; List<Planet> planets = container.getItemIds(); for (int i=0; i<planets.size(); i++)

names[i] = planets.get(i).getName(); xaxis.setCategories(names); xaxis.setTitle("Planet"); conf.addxAxis(xaxis);

The result can be seen in Figure 19.10, “Table and Chart Bound to a Container”.

Figure 19.10. Table and Chart Bound to a Container

19.7. Advanced Uses

19.7.1. Server-Side Rendering and Exporting

In addition to using charts in Vaadin UIs, you may also need to provide them as images or in downloadable documents. Vaadin Charts can be rendered on the server-side using a headless JavaScript execution environment, such as PhantomJS [http://phantomjs.org/].

Vaadin Charts supports a HighCharts remote export service, but the SVG Generator based on PhantomJS is almost as easy to use and allows much more powerful uses.

Using a Remote Export Service

HighCharts has a simple built-in export functionality that does the export in a remote export server. HighCharts provides a default export service, but you can also configure your own.

You can enable the built-in export function by setting setExporting(true) in the chart configuration.

chart.getConfiguration().setExporting(true);

432

Advanced Uses

Vaadin Charts

To configure it further, you can provide a Exporting object with custom settings.

//Create the export configuration Exporting exporting = new Exporting(true);

//Customize the file name of the download file exporting.setFilename("mychartfile.pdf");

//Enable export of raster images exporting.setEnableImages(true);

//Use the exporting configuration in the chart chart.getConfiguration().setExporting(exporting);

If you only want to enable download, you can disable the print button as follows:

ExportButton printButton = new ExportButton(); printButton.setEnabled(false); exporting.setPrintButton(printButton);

The functionality uses a HighCharts export service by default. To use your own, you need to set up one and then configure it in the exporting configuration as follows:

exporting.setUrl("http://my.own.server.com");

Using the SVG Generator

The SVGGenerator in Vaadin Charts provides an advanced way to render the Chart into SVG format on the server-side. SVG is well supported by many applications, can be converted to virtually any other graphics format, and can be passed to PDF report generators.

The generator uses PhantomJS to render the chart on the server-side.You need to install it from phantomjs.org [http://phantomjs.org/]. After installation, PhantomJS should be in your system path. If not, you can set the phantom.exec system property for the JRE to point to the PhantomJS binary.

To generate the SVG image content as a string (it's XML), simply call the generate() method in the SVGGenerator singleton and pass it the chart configuration.

String svg = SVGGenerator.getInstance()

.generate(chart.getConfiguration());

You can then use the SVG image as you like, for example, for download from a StreamResource, or include it in a HTML, PDF, or other document. You can use SVG tools such as the Batik [http://xmlgraphics.apache.org/batik/] or iText [http://itextpdf.com/] libraries to generate documents. For a complete example, you can check out the Charts Export Demo from the Subversion repository at http://dev.vaadin.com/svn/addons/vaadin-charts/chart-export-demo.

Server-Side Rendering and Exporting

433

434

Chapter 20

Vaadin Timeline

20.1. Overview ..............................................................................................

435

20.2. Using Timeline .....................................................................................

439

20.3. Code example ......................................................................................

442

20.1. Overview

The Timeline is a charting component included in the Vaadin Charts add-on, separate from the Chart component. Its purpose is to give the user an intuitive understanding of events and trends on a horizontal timeline axis.

Timeline uses its own representation for the data series, different from the Chart and more optimized for updating. You can represent almost any time-related statistical data that has a timevalue mapping. Multiple data sources can be used to allow comparison between data.

Book of Vaadin

435

Vaadin Timeline

Figure 20.1. Vaadin Timeline Add-On Component

A timeline allows representing time-related data visually as graphs instead of numerical values. They are used commonly in almost all fields of business, science, and technology, such as in project management to map out milestones and goals, in geology to map out historical events, and perhaps most prominently in the stock market.

With Vaadin Timeline, you can represent almost any time-related statistical data that has a timevalue mapping. Even several data sources can be used for comparison between data.This allows the user to better grasp of changes in the data and antipate forthcoming trends and problems.

Vaadin Timeline can be easily included in a Vaadin application and is highly customizable to suit almost any purpose. Timeline supports multiple graph types as well as events and markers. The user interaction with the Timeline is straight-forward and simple.

Book of Vaadin currently includes only an introduction to Vaadin Timeline. Please refer to the product documentation included in the installation package for further details.

Licensing

Vaadin Timeline is a commercial product licensed under a dual-licensing scheme. The AGPL (GNU Affero General Public License) allows open-source development. CVAL (Commercial Vaadin Add-On License) needs to be purchased for closed-source use, including web deployments as well as intranet use.

Commercial licenses can be purchased from the Vaadin Directory, where you can also find the license details and download the Vaadin Timeline.

Graph types

The Vaadin Timeline supports three graph types:

436

Licensing

Vaadin Timeline

Line graphs

Useful for representing continuous data, such as temperature changes or changes in stock price.

Bar graphs

Useful for representing discrete or discontinuous data, such as market share or forum posts.

Scatter graphs

Useful for representing discrete or discontinuous data.

If you have several graphs in the timeline, you can also stack them on top of each other instead of drawing them on top of each other by setting setGraphStacking() in Timeline to true.

Interaction Elements

The user can interact with the Vaadin Timeline in several ways.

On the bottom of the timeline there is a scrollbar area where you can move the time forward or backward in time by dragging the time range box or by clicking the left and right arrow buttons. You can change the time range by resizing the range box in the scrollbar area. You can also zoom with the mouse wheel when the pointer is inside the component.

Figure 20.2. Scrollbar Area

The middle area of the timeline is the main area where the selected time range is displayed.Time scale is shown below the main area. The time scale used depends on the zoom level and can be a time unit from hours to years. Value scale is displayed on the right side of the main area. The scale can be either a static value range or a range calculated from the displayed data set. The user can move in time by dragging the main area with the mouse left and right and zoom in and out by using the mouse wheel.

Figure 20.3. Main Area

Interaction Elements

437

Vaadin Timeline

You can select a preset zoom level with the buttons on the top the Timeline. This will change the displayed time range to match the zoom level. The zoom levels are fully customizable to suit the time range in the API.

Figure 20.4. Preset Zoom Buttons

The current time range is shown at the top-right corner of the component. Clicking the dates makes them editable, so that you can manually change them. Graph legend is shown below the time range. The legend explains what is represented by each bar on the graph and displays the current value when the user moves the mouse cursor over the graph.

Figure 20.5. Current Time Range and Graph Legend

Finally, the available chart modes are shown below the preset zoom levels options. The available graph modes can be set from the API.

Figure 20.6. Chart Mode

You can use or hide any of the features above can be shown or hidden depending on your needs. For example, if you only need to display a graph without any controls, you can hide all them from the API.

Event Markers

In addition to graphs, the timeline can have events. An event can be, for example, the time of a published advertisement in a graph that displays website hits. Combining the event data with the graphs enables the user to observe the relevance of the advertisement to the website hits visually.

Vaadin Timeline provides two types of event markers, as illustrated in Figure 20.7, “Timeline Event Markers”.

438

Event Markers

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]