Skip to content

Commit 19380fd

Browse files
authored
Merge pull request #1 from DevExpress-Examples/nk-add-gauges
add gauges
2 parents 8ea9e3a + 34e7f6f commit 19380fd

File tree

7 files changed

+120
-22
lines changed

7 files changed

+120
-22
lines changed

CS/AspNetMvcDashboardApp/App_Data/Dashboards/dashboard1.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,33 @@
6868
<Value DefaultId="DataItem0" />
6969
</Values>
7070
</Pie>
71+
<Gauge ComponentName="gaugeDashboardItem1" Name="Gauges with modified ticks and font weight" DataSource="DataSource1" DataMember="SalesPerson">
72+
<DataItems>
73+
<Measure DataMember="Extended Price" DefaultId="DataItem0" />
74+
<Measure DataMember="Quantity" DefaultId="DataItem1" />
75+
</DataItems>
76+
<GaugeElement>
77+
<ActualValue DefaultId="DataItem0" />
78+
<AbsoluteVariationNumericFormat />
79+
<PercentVariationNumericFormat />
80+
<PercentOfTargetNumericFormat />
81+
</GaugeElement>
82+
<GaugeElement>
83+
<ActualValue DefaultId="DataItem1" />
84+
<AbsoluteVariationNumericFormat />
85+
<PercentVariationNumericFormat />
86+
<PercentOfTargetNumericFormat />
87+
</GaugeElement>
88+
</Gauge>
7189
</Items>
7290
<LayoutTree>
7391
<LayoutGroup>
7492
<LayoutItem DashboardItem="gridDashboardItem1" Weight="63.807415605976757" />
7593
<LayoutGroup Orientation="Vertical" Weight="136.19258439402324">
76-
<LayoutItem DashboardItem="chartDashboardItem1" Weight="136.19258439402324" />
94+
<LayoutGroup Weight="136.19258439402324">
95+
<LayoutItem DashboardItem="gaugeDashboardItem1" Weight="136.19258439402324" />
96+
<LayoutItem DashboardItem="chartDashboardItem1" Weight="136.19258439402324" />
97+
</LayoutGroup>
7798
<LayoutItem DashboardItem="pieDashboardItem1" Weight="136.19258439402324" />
7899
</LayoutGroup>
79100
</LayoutGroup>
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
11
function onBeforeRender(s, e) {
22
var dashboardControl = s.GetDashboardControl();
33
var viewerApiExtension = dashboardControl.findExtension('viewerApi');
4-
if (viewerApiExtension)
4+
if (viewerApiExtension) {
55
viewerApiExtension.on('itemWidgetOptionsPrepared', customizeWidgetOptions);
6+
viewerApiExtension.on('itemWidgetUpdated', customizeWidget);
7+
viewerApiExtension.on('itemWidgetCreated', customizeWidget);
8+
};
69
}
710
function customizeWidgetOptions(e) {
811
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GridItem) {
912
e.options.hoverStateEnabled = true
1013
};
1114
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.ChartItem) {
12-
e.options.tooltip = {
13-
enabled: false
14-
};
15+
e.options.tooltip.enabled = false;
1516
e.options.animation = {
17+
...e.options.animation,
1618
enabled: true,
1719
duration: 1000
1820
};
1921
e.options.onArgumentAxisClick = function (info) {
20-
info.component.getAllSeries()[0].getPointsByArg(info.argument)[0].showTooltip()
22+
info.component.getAllSeries()[0].getPointsByArg(info.argument)[0].showTooltip();
2123
}
2224
};
2325
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.PieItem) {
2426
e.options.legend = {
27+
...e.options.legend,
2528
visible: true,
2629
border: {
30+
...e.options.legend.border,
2731
visible: true
2832
}
2933
};
3034
e.options.animation = {
35+
...e.options.animation,
3136
enabled: true,
3237
duration: 1000
3338
};
3439
}
40+
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GaugeItem) {
41+
var gaugesCollection = e.dashboardItem.gauges();
42+
gaugesCollection.forEach(element => {
43+
if (element.actualValue().dataMember() == 'Extended Price') {
44+
e.options.scale.tick.tickInterval = 1000
45+
}
46+
});
47+
}
3548
}
49+
function customizeWidget(e) {
50+
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GaugeItem) {
51+
var gaugesCollection = e.getWidget();
52+
gaugesCollection.forEach(element => {
53+
element.option('scale.label.font.weight', '600');
54+
});
55+
}
56+
}

Readme.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/371736934/21.2.1%2B)
32
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1002174)
43
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
54
<!-- default badges end -->
65

76
# Dashboard for MVC - How to access API of underlying widgets
8-
<!-- run online -->
9-
**[[Run Online]](https://codecentral.devexpress.com/371736934/)**
10-
<!-- run online end -->
117

12-
The following example shows how to customize options of underlying widgets in ASP.NET MVC. For this, you need to handle the [onItemWidgetOptionsPrepared](https://docs.devexpress.com/Dashboard/js-DevExpress.Dashboard.ViewerApiExtensionOptions?p=netframework#js_devexpress_dashboard_viewerapiextensionoptions_onitemwidgetoptionsprepared) event.
8+
The following example shows how to customize options of underlying widgets in ASP.NET MVC.
139

10+
Use the [ViewerApiExtension.on](https://docs.devexpress.com/Dashboard/js-DevExpress.Dashboard.ViewerApiExtension#js_devexpress_dashboard_viewerapiextension_on) and [ViewerApiExtension.off](https://docs.devexpress.com/Dashboard/js-DevExpress.Dashboard.ViewerApiExtension#js_devexpress_dashboard_viewerapiextension_off) methods to subscribe and unsubscribe from the events.
11+
12+
The Web Dashboard renders an underlying widget as follows:
13+
14+
1. The Web Dashboard loads the widget’s default configuration.
15+
16+
The [onItemWidgetOptionsPrepared](https://docs.devexpress.com/Dashboard/js-DevExpress.Dashboard.ViewerApiExtensionOptions#js_devexpress_dashboard_viewerapiextensionoptions_onitemwidgetoptionsprepared) event is raised. Handle this event to customize the DevExtreme widget’s options before the widget is rendered.
17+
18+
1. The Web Dashboard renders the UI component with the configured options.
19+
20+
The [onItemWidgetCreated](https://docs.devexpress.com/Dashboard/js-DevExpress.Dashboard.ViewerApiExtensionOptions#js_devexpress_dashboard_viewerapiextensionoptions_onitemwidgetcreated) event is raised. It occurs once for each UI component when the dashboard is loaded to the client. You can use this event to customize the UI component instance.
21+
22+
1. The UI component is updated (for example, when you apply filters or change parameter values).
23+
24+
The [onItemWidgetUpdated](https://docs.devexpress.com/Dashboard/js-DevExpress.Dashboard.ViewerApiExtensionOptions#js_devexpress_dashboard_viewerapiextensionoptions_onitemwidgetupdated) event is raised. It occurs every time the UI component should be re-rendered.
25+
1426
The customized options are listed below:
1527

1628
- The hovered grid row is highlighted in the underlying [dxDataGrid](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxDataGrid/).
1729
- A standard tooltip that appears when a user hovers over a chart's series point is disabled.
1830
- A custom tooltip appears when a user clicks a label on the chart's argument axis. The [onArgumentAxisClick](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxChart/Configuration/#onArgumentAxisClick) property executes a function that invokes the custom tooltip.
19-
- The [animation](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxChart/Configuration/animation/) is enabled for the [dxChart](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxChart/) and [dxPieChart](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxPieChart/) widgets.
20-
- The [dxPieChart](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxPieChart/) widget displays a legend.
31+
- The [animation](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxChart/Configuration/animation/) is enabled for the [dxChart](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxChart/) and [dxPieChart](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxPieChart/) UI components.
32+
- The [dxPieChart](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxPieChart/) UI component displays a legend.
33+
- The font weight and an interval between major ticks are modified in the [dxCircularGauge](https://js.devexpress.com/DevExtreme/ApiReference/UI_Components/dxCircularGauge/) UI component.
2134

2235
## Files to Review
2336

VB/AspNetMvcDashboardApp/App_Data/Dashboards/dashboard1.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,33 @@
6868
<Value DefaultId="DataItem0" />
6969
</Values>
7070
</Pie>
71+
<Gauge ComponentName="gaugeDashboardItem1" Name="Gauges 1" DataSource="DataSource1" DataMember="SalesPerson">
72+
<DataItems>
73+
<Measure DataMember="Extended Price" DefaultId="DataItem0" />
74+
<Measure DataMember="Quantity" DefaultId="DataItem1" />
75+
</DataItems>
76+
<GaugeElement>
77+
<ActualValue DefaultId="DataItem0" />
78+
<AbsoluteVariationNumericFormat />
79+
<PercentVariationNumericFormat />
80+
<PercentOfTargetNumericFormat />
81+
</GaugeElement>
82+
<GaugeElement>
83+
<ActualValue DefaultId="DataItem1" />
84+
<AbsoluteVariationNumericFormat />
85+
<PercentVariationNumericFormat />
86+
<PercentOfTargetNumericFormat />
87+
</GaugeElement>
88+
</Gauge>
7189
</Items>
7290
<LayoutTree>
7391
<LayoutGroup>
7492
<LayoutItem DashboardItem="gridDashboardItem1" Weight="63.807415605976757" />
7593
<LayoutGroup Orientation="Vertical" Weight="136.19258439402324">
76-
<LayoutItem DashboardItem="chartDashboardItem1" Weight="136.19258439402324" />
94+
<LayoutGroup Weight="136.19258439402324">
95+
<LayoutItem DashboardItem="gaugeDashboardItem1" Weight="136.19258439402324" />
96+
<LayoutItem DashboardItem="chartDashboardItem1" Weight="136.19258439402324" />
97+
</LayoutGroup>
7798
<LayoutItem DashboardItem="pieDashboardItem1" Weight="136.19258439402324" />
7899
</LayoutGroup>
79100
</LayoutGroup>

VB/AspNetMvcDashboardApp/AspNetMvcDashboardApp.vbproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
@@ -226,6 +226,7 @@
226226
</None>
227227
<Content Include="App_Data\NWind.mdf" />
228228
<Content Include="Content\DashboardThumbnail\dashboard1.png" />
229+
<Content Include="Scripts\WidgetsCustomization.js" />
229230
<Content Include="Views\Web.config" />
230231
<Content Include="Web.config" />
231232
<Content Include="Views\_ViewStart.vbhtml" />
@@ -295,4 +296,4 @@
295296
</PropertyGroup>
296297
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
297298
</Target>
298-
</Project>
299+
</Project>
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
11
function onBeforeRender(s, e) {
22
var dashboardControl = s.GetDashboardControl();
33
var viewerApiExtension = dashboardControl.findExtension('viewerApi');
4-
if (viewerApiExtension)
4+
if (viewerApiExtension) {
55
viewerApiExtension.on('itemWidgetOptionsPrepared', customizeWidgetOptions);
6+
viewerApiExtension.on('itemWidgetUpdated', customizeWidget);
7+
viewerApiExtension.on('itemWidgetCreated', customizeWidget);
8+
};
69
}
710
function customizeWidgetOptions(e) {
811
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GridItem) {
912
e.options.hoverStateEnabled = true
1013
};
1114
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.ChartItem) {
12-
e.options.tooltip = {
13-
enabled: false
14-
};
15+
e.options.tooltip.enabled = false;
1516
e.options.animation = {
17+
...e.options.animation,
1618
enabled: true,
1719
duration: 1000
1820
};
1921
e.options.onArgumentAxisClick = function (info) {
20-
info.component.getAllSeries()[0].getPointsByArg(info.argument)[0].showTooltip()
22+
info.component.getAllSeries()[0].getPointsByArg(info.argument)[0].showTooltip();
2123
}
2224
};
2325
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.PieItem) {
2426
e.options.legend = {
27+
...e.options.legend,
2528
visible: true,
2629
border: {
30+
...e.options.legend.border,
2731
visible: true
2832
}
2933
};
3034
e.options.animation = {
35+
...e.options.animation,
3136
enabled: true,
3237
duration: 1000
3338
};
3439
}
40+
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GaugeItem) {
41+
var gaugesCollection = e.dashboardItem.gauges();
42+
gaugesCollection.forEach(element => {
43+
if (element.actualValue().dataMember() == 'Extended Price') {
44+
e.options.scale.tick.tickInterval = 1000
45+
}
46+
});
47+
}
3548
}
49+
function customizeWidget(e) {
50+
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GaugeItem) {
51+
var gaugesCollection = e.getWidget();
52+
gaugesCollection.forEach(element => {
53+
element.option('scale.label.font.weight', '600');
54+
});
55+
}
56+
}

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"runOnWeb": true,
2+
"runOnWeb": false,
33
"autoGenerateVb": false
44
}

0 commit comments

Comments
 (0)