forked from syncfusion/ej2-aspnetmvc-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrendlines.cshtml
245 lines (233 loc) · 11 KB
/
Trendlines.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
@using Syncfusion.EJ2;
@section ControlsSection{
<div>
<div class="col-lg-9 control-section">
<div>
@Html.EJS().Chart("container").Series(series =>
{
series.Trendlines(tl=> { tl.Type(Syncfusion.EJ2.Charts.TrendlineTypes.Linear).Width(3).Name("Linear").Fill("#C64A75").Add(); })
.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)
.XName("x").YName("y").Marker(mr=>mr.Visible(true))
.DataSource("series1").Name("Rupees").Width(2).Add();
}).PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.MajorGridLines(mg=>mg.Width(0))
).PrimaryYAxis(py => py.Title("Rupees against Dollars").Interval(10)
.MajorTickLines(mt=>mt.Width(0)).LineStyle(ls=>ls.Width(0))
).ChartArea(area => area.Border(br=>br.Color("transparent"))
).Title("Historical Indian Rupee Rate (INR USD)").LegendSettings(lg => lg.Visible(true)
).Tooltip(tt => tt.Enable(true)).Load("load").Render()
</div>
</div>
<div class="col-lg-3 property-section">
<table id="property" title="Properties" style="width: 100%">
<tbody>
<tr style="height: 50px">
<td style="width: 50%">
<div>
TrendLine Type:
</div>
</td>
<td style="width: 50%;">
<div>
@Html.EJS().DropDownList("trendLineType").Index(0).DataSource(ViewBag.trendlineTypes).Value("Linear").Change("changeType").Render()
</div>
</td>
</tr>
<tr id="" style="height: 50px">
<td style="width: 80%">
<div> Forward Forecast:</div>
</td>
<td style="width: 20%;">
<div style="margin-top: 0px;">
@Html.EJS().NumericTextBox("forwardForecast").Change("changeForward").Value(0).Max(20).Min(1).Width("120").Step(1).Render()
</div>
</td>
</tr>
<tr id="" style="height: 50px">
<td style="width: 80%">
<div>Backward Forecast:</div>
</td>
<td style="width: 20%;">
<div style="margin-top: 0px;">
@Html.EJS().NumericTextBox("backwardForecast").Change("changeBackward").Value(0).Max(20).Min(1).Width("120").Step(1).Render()
</div>
</td>
</tr>
<tr id="" style="height: 50px">
<td style="width: 80%">
<div>Polynomial Order:</div>
</td>
<td style="width: 20%;">
<div style="margin-top: 0px;">
@Html.EJS().NumericTextBox("polynomialOrder").Change("changeOrder").Enabled(false).Value(0).Max(20).Min(1).Width("120").Step(1).Render()
</div>
</td>
</tr>
<tr id="" style="height: 50px">
<td style="width: 80%">
<div>Period:</div>
</td>
<td style="width: 20%;">
<div style="margin-top: 0px;">
@Html.EJS().NumericTextBox("period").Change("changePeriod").Enabled(false).Value(0).Max(20).Min(1).Width("120").Step(1).Render()
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<style>
@*custom code start*@
#control-container {
padding: 0px !important;
}
@*custom code end*@
#container_Series_0_TrendLine_0 {
stroke-dasharray: 10px 10px;
stroke-linejoin: round; stroke-linecap: round;
-webkit-animation: dash 1s linear infinite;
animation: dash 1s linear infinite;
}
@@-webkit-keyframes dash {
100% {
stroke-dashoffset: -20px;
}
}
@@keyframes dash {
100% {
stroke-dashoffset: -20px;
}
}
</style>
<script type="text/javascript">
var series1 = [];
var yValue = [7.66, 8.03, 8.41, 8.97, 8.77, 8.20, 8.16, 7.89, 8.68, 9.48, 10.11, 11.36, 12.34, 12.60, 12.95,
13.91, 16.21, 17.50, 22.72, 28.14, 31.26, 31.39, 32.43, 35.52, 36.36,
41.33, 43.12, 45.00, 47.23, 48.62, 46.60, 45.28, 44.01, 45.17, 41.20, 43.41, 48.32, 45.65, 46.61, 53.34, 58.53];
var point1;
var i;
var j = 0;
for (i = 1973; i <= 2013; i++) {
point1 = { x: i, y: yValue[j] };
series1.push(point1);
j++;
}
var powerData = [
{ x: 1, y: 10 }, { x: 2, y: 50 }, { x: 3, y: 80 }, { x: 4, y: 110 },
{ x: 5, y: 180 }, { x: 6, y: 220 }, { x: 7, y: 300 }, { x: 8, y: 370 }, { x: 9, y: 490 }, { x: 10, y: 500 }
];
var load = function (args) {
var selectedTheme = themeName ? themeName : 'Material';
args.chart.theme = (selectedTheme.charAt(0).toUpperCase() + selectedTheme.slice(1)).replace(/-dark/i, "Dark").replace(/contrast/i, 'Contrast');
};
function changeForward(){
var chart = document.getElementById("container").ej2_instances[0];
var forward = document.getElementById("forwardForecast").ej2_instances[0];
chart.series[0].animation.enable = false;
chart.series[0].trendlines[0].forwardForecast = forward.value;
chart.refresh();
}
function changeBackward() {
var chart = document.getElementById("container").ej2_instances[0];
var backward = document.getElementById("backwardForecast").ej2_instances[0];
chart.series[0].animation.enable = false;
chart.series[0].trendlines[0].backwardForecast = backward.value;
chart.refresh();
}
function changeOrder() {
var chart = document.getElementById("container").ej2_instances[0];
var polynomial = document.getElementById("polynomialOrder").ej2_instances[0];
chart.series[0].animation.enable = false;
chart.series[0].trendlines[0].polynomialOrder = polynomial.value;
chart.refresh();
}
function changePeriod() {
var chart = document.getElementById("container").ej2_instances[0];
var periodValue = document.getElementById("period").ej2_instances[0];
chart.series[0].animation.enable = false;
chart.series[0].trendlines[0].period = periodValue.value;
chart.refresh();
}
function changeType() {
var chart = document.getElementById("container").ej2_instances[0];
var trend = document.getElementById("trendLineType").ej2_instances[0];
chart.series[0].animation.enable = false;
chart.series[0].dataSource = [];
chart.series[0].trendlines[0].type = trend.value;
chart.series[0].trendlines[0].name = trend.value;
var forwardForecast;
var backwardForecast;
var polynomialOrder;
var period;
if (trend.value !== 'Power') {
chart.series[0].dataSource = series1;
chart.series[0].name = 'Rupees';
chart.primaryXAxis.title = '';
chart.primaryYAxis.interval = 10;
chart.primaryYAxis.title = 'Rupees against Dollars';
chart.title = 'Historical Indian Rupee Rate (INR USD)';
if (trend.value === 'MovingAverage') {
chart.series[0].trendlines[0].marker.visible = false;
}
}
else {
chart.series[0].dataSource = powerData;
chart.series[0].name = 'Meters';
chart.primaryXAxis.title = 'Seconds';
chart.primaryYAxis.title = 'Meters';
chart.primaryYAxis.interval = 100;
chart.title = 'Distance Measurement';
}
if (trend.value !== 'Polynomial' && trend.value !== 'MovingAverage') {
period = polynomialOrder = true;
forwardForecast = backwardForecast = false;
}
else if (trend.value === 'MovingAverage') {
period = false;
forwardForecast = backwardForecast = polynomialOrder = true;
}
else {
forwardForecast = backwardForecast = polynomialOrder = false;
period = true;
}
document.getElementById("forwardForecast").ej2_instances[0].enabled = !forwardForecast;
document.getElementById("backwardForecast").ej2_instances[0].enabled = !backwardForecast;
document.getElementById("polynomialOrder").ej2_instances[0].enabled = !polynomialOrder;
document.getElementById("period").ej2_instances[0].enabled = !period;
chart.refresh();
}
</script>
}
@*custom code start*@
@section Meta{
<meta name="description" content="This example demonstrates the Trendlines in ASP.NET MVC Chart control. Explore here for more details."/>
}
@*custom code end*@
@section ActionDescription{
<p>
This sample visualizes the trend of Indian rupees and US dollar variation with trendline in the chart.
The type of trend line can be changed by using <code>TrendLine Type</code>, forward and backward forecasting of trendlines can be changed by <code>Forward Forecasting</code> and <code>Backward Forecast</code> respectively.
Polynomial and period for a trendlines can be changed by using <code>Polynomial order</code> and <code>Period</code>.
</p>
}
@section Description{
<p>
In this example, you can see how to render and configure the Trend Lines. You can use
<code>border</code>,
<code>fill</code> properties to customize the area.
</p>
<p>
Tooltip is enabled in this example, to see the tooltip in action, hover a point or tap on a point in touch enabled devices.
</p>
<p>
More information on the Trend Lines can be found in this
<a target="_blank" href="http://ej2.syncfusion.com/documentation/chart/api-series.html#type-chartseriestype">documentation section</a>.
</p>
}
@section Title{
<title>ASP.NET MVC Chart Trendlines Example - Syncfusion Demos </title>
}
@section Header{
<h1 class='sb-sample-text'>Example of Trendlines in ASP.NET MVC Chart Control</h1>
}