Skip to content

Commit dc48551

Browse files
author
nicogeburek
committed
new tutorial
1 parent 43495e3 commit dc48551

4 files changed

Lines changed: 173 additions & 0 deletions

File tree

137 KB
Loading
226 KB
Loading
194 KB
Loading
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
title: Visualize Data from the Northwind Service
3+
description: Learn how to visualize data with a `VizFrame`.
4+
auto_validation: true
5+
time: 20
6+
tags: [ tutorial>beginner, programming-tool>sapui5, software-product>sap-launchpad-service, software-product>sap-fiori, topic>user-interface, programming-tool>html5, topic>cloud, tutorial>free-tier]
7+
primary_tag: programming-tool>odata
8+
author_name: Nico Geburek
9+
author_profile: https://github.com/nicogeburek
10+
---
11+
12+
## Prerequisites
13+
- You have previously created a SAPUI5 based project, e.g. with the [easy-ui5 generator](sapui5-fiori-cf-create-project).
14+
- You have [added the Northwind Service as a data source and default model](sapui5-fiori-cf-display-data) to your application.
15+
- You have version 3.1.4 or higher of the [easy-ui5 generator](cp-cf-sapui5-local-setup) installed.
16+
17+
## Details
18+
### You will learn
19+
- How to use a sub-generator to add a new view
20+
- How to add a `VizFrame` to visualize data
21+
- How to manually navigate between SAPUI5 views
22+
23+
---
24+
25+
[ACCORDION-BEGIN [Step : ](Add a new view)]
26+
27+
Add a new view to your SAPUI5 application by using an `easy-ui5` sub-generator.
28+
29+
**Open** a new terminal session on root level of your project and execute:
30+
31+
```Terminal
32+
yo easy-ui5 project newview
33+
```
34+
35+
| Parameter | Value
36+
| :------------- | :-------------
37+
| What is the name of the new view? | **`Sales`**
38+
| Would you like to create a corresponding controller as well? | **`Yes`**
39+
| Do you want to add an OPA5 page object? | **`No`**
40+
| Would you like to create a route in the manifest? | **`Yes`**
41+
42+
The routes are added to the `uimodule/webapp/manifest.json` file. The generator asks you whether you want to overwrite the `manifest.json` file, which is necessary in this case, so type `yes` when prompted.
43+
44+
[DONE]
45+
[ACCORDION-END]
46+
[ACCORDION-BEGIN [Step : ](Inspect the modifications)]
47+
48+
As you can see in the log, the generator created a new view with its corresponding controller. It also modified the `uimodule/webapp/manifest.json` by adding a new route as well as a new target. You can see the pattern for the new `Sales` route is `RouteSales`. This is the piece that we will later attach to the URL of our application to reach this view.
49+
50+
![screen shot of manifest with new route](manifest.png)
51+
52+
[DONE]
53+
[ACCORDION-END]
54+
[ACCORDION-BEGIN [Step : ](Add the `VizFrame`)]
55+
56+
The `webapp/view/Sales.view.xml` will hold the `VizFrame` that visualizes the data from the Northwind Service. **Remove** the entire content view and replace it with the below code.
57+
58+
```XML
59+
<mvc:View
60+
controllerName="tutorial.products.controller.Sales"
61+
displayBlock="true"
62+
xmlns="sap.m"
63+
xmlns:mvc="sap.ui.core.mvc"
64+
65+
xmlns:layout="sap.ui.layout"
66+
xmlns:viz="sap.viz.ui5.controls"
67+
xmlns:viz.data="sap.viz.ui5.data"
68+
xmlns:viz.feeds="sap.viz.ui5.controls.common.feeds">
69+
70+
<Page title="{i18n>title}" id="Sales" >
71+
<content>
72+
<layout:FixFlex id="chartFixFlex" minFlexSize="250">
73+
<layout:flexContent>
74+
<viz:Popover id="idPopOver" connect="id`VizFrame`"></viz:Popover>
75+
<viz:`VizFrame`
76+
id="id`VizFrame`"
77+
uiConfig="{applicationSet:'fiori'}"
78+
height="100%"
79+
width="100%"
80+
vizType="timeseries_line"
81+
vizProperties="{
82+
title: {
83+
text: 'Sales by Years'
84+
},
85+
plotArea: {
86+
dataLabel: {
87+
visible: false
88+
},
89+
window: {
90+
start: 'firstDataPoint',
91+
end: 'lastDataPoint'
92+
}
93+
}
94+
}" >
95+
<viz:dataset>
96+
<viz.data:FlattenedDataset data="{/Summary_of_Sales_by_Years}">
97+
<viz.data:dimensions>
98+
<viz.data:DimensionDefinition
99+
name="ShippedDate"
100+
value="{ShippedDate}"
101+
dataType="date"/>
102+
</viz.data:dimensions>
103+
<viz.data:measures>
104+
<viz.data:MeasureDefinition
105+
name="Subtotal"
106+
value="{Subtotal}"/>
107+
</viz.data:measures>
108+
</viz.data:FlattenedDataset>
109+
</viz:dataset>
110+
<viz:feeds>
111+
<viz.feeds:FeedItem
112+
id="valueAxisFeed"
113+
uid="valueAxis"
114+
type="Measure"
115+
values="Subtotal" />
116+
<viz.feeds:FeedItem
117+
id="timeAxisFeed"
118+
uid="timeAxis"
119+
type="Dimension"
120+
values="ShippedDate" />
121+
</viz:feeds>
122+
</viz:`VizFrame`>
123+
</layout:flexContent>
124+
</layout:FixFlex>
125+
</content>
126+
</Page>
127+
</mvc:View>
128+
```
129+
130+
This new code uses additional SAPUI5 libraries that are referenced at the top of the file. These are necessary in order to use the layout and `VizFrame` related controls. If you look at the code closely, you will notice that it defines a new ``VizFrame`` of type `timeseries_line`. The dataset (`FlattenedDataSet`) is bound to the `/Summary_of_Sales_by_Years` entity of the Northwind OData Service. The dimension (`DimensionDefinition`) is `ShippedDate`, which represents time and is therefore of type `date`. The measure (`MeasureDefinition`) is the `Subtotal` of sales.
131+
132+
You can read more about `VizFrame`s in the [SAPUI5 API Reference](https://sapui5.hana.ondemand.com/#/api/sap.viz.ui5.controls.`VizFrame`%23overview) and check out some samples in the [SAPUI5 Samples](https://sapui5.hana.ondemand.com/#/entity/sap.viz.ui5.controls.`VizFrame`). `VizFrame`s even have their own [documentation](https://sapui5.hana.ondemand.com/docs/vizdocs/index.html) that lists all available properties, events, bindings, and scales.
133+
134+
[DONE]
135+
[ACCORDION-END]
136+
[ACCORDION-BEGIN [Step : ](Navigate to the new view)]
137+
138+
In order to see the new view in your application in the browser, you have to navigate there manually using the pattern you already inspected in step 2. If your application is running in a Fiori Launchpad, attach `&/RouteSales` to the URL. If your application runs standalone, attach `#/RouteSales` to the URL. There is a difference between these two scenarios, because your application in the Fiori Launchpad already requires a hash (`#`) to navigate to it and there is only one hash allowed in a URL.
139+
140+
![screen shot of sales view in the browser](salesview.png)
141+
142+
[DONE]
143+
[ACCORDION-END]
144+
[ACCORDION-BEGIN [Step : ](Implement a popover)]
145+
146+
You might have noticed that you can hover over the single data points of the line chart and click them, but nothing happens yet. Insert the below `onAfterRendering` method into the `Sales.controller.js` to connect the `VizFrame` with the popover, which we already defined in our `Sales.view.xml` (step 3).
147+
148+
```javascript [7-11]
149+
150+
sap.ui.define([
151+
"tutorial/products/controller/BaseController"
152+
], function (Controller) {
153+
"use strict";
154+
155+
return Controller.extend("tutorial.products.controller.Sales", {
156+
onAfterRendering: function () {
157+
const o`VizFrame` = this.o`VizFrame` = this.getView().byId("id`VizFrame`");
158+
const oPopOver = this.getView().byId("idPopOver");
159+
oPopOver.connect(o`VizFrame`.getVizUid());
160+
}
161+
});
162+
});
163+
```
164+
165+
After saving the file, your browser should automatically refresh the page. You can now click on any data point to get the popover with its exact data.
166+
167+
![screen shot of popover](popover.png)
168+
169+
[VALIDATE_1]
170+
[ACCORDION-END]
171+
172+
173+
---

0 commit comments

Comments
 (0)