forked from syncfusion/ej2-aspnetmvc-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartAxisLabels.cshtml
192 lines (188 loc) · 8.67 KB
/
SmartAxisLabels.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
@using Syncfusion.EJ2;
<script src="~/Scripts/theme-color.js"></script>
@section ControlsSection{
<div class="col-lg-9 control-section">
<div class="content-wrapper">
<div style="width:92%">
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).XName("xValue").YName("yValue")
.Marker(mr=>mr.DataLabel(dl=>dl.Visible(true).Position(Syncfusion.EJ2.Charts.LabelPosition.Top).Font(ff => ff.FontWeight("600").Color("#ffffff"))))
.DataSource(ViewBag.dataSource).Name("Users")
.Add();
}).PrimaryXAxis(px => px.LabelIntersectAction(Syncfusion.EJ2.Charts.LabelIntersectAction.Hide)
.Interval(1).ValueType(Syncfusion.EJ2.Charts.ValueType.Category).MajorGridLines(mg=>mg.Width(0))
).PrimaryYAxis(py => py.MajorGridLines(mg=>mg.Width(0)).MajorTickLines(mt=>mt.Width(0)).LineStyle(ls=>ls.Width(0)).LabelStyle(ls=>ls.Color("transparent"))
).Title("Internet Users in Millions").ChartArea(area => area.Border(br=>br.Color("transparent"))).Tooltip(tt => tt.Enable(true)).LegendSettings(lg => lg.Visible(false)).Load("load").PointRender("labelRender").Render()
</div>
</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: 40%">
<div>Intersect Action:</div>
</td>
<td style="width: 60%;">
<div>
@Html.EJS().DropDownList("selmode").Index(0).DataSource(ViewBag.data).Value("Hide").Change("valueChange").Width("120").Render()
</div>
</td>
</tr>
<tr style="height: 50px">
<td style="width: 60%">
<div>Edge Label Placement:</div>
</td>
<td style="width: 40%;">
<div>
@Html.EJS().DropDownList("edgemode").Index(0).DataSource(ViewBag.data1).Value("None").Change("edgeModeChange").Render()
</div>
</td>
</tr>
<tr style="height: 50px">
<td style="width: 60%">
<div>Label Position:</div>
</td>
<td style="width: 40%;">
<div>
@Html.EJS().DropDownList("position").Index(0).DataSource(ViewBag.data2).Value("Outside").Change("positionChange").Render()
</div>
</td>
</tr>
<tr style="height: 50px">
<td style="width: 50%">
<div>
Enable Trim:
</div>
</td>
<td style="width: 50%;">
<div>
<input type="checkbox" id="Trim" unchecked="">
</div>
</td>
</tr>
<tr style="height: 50px">
<td style="width: 60%">
<div>Maximum Label Width:</div>
</td>
<td style="width: 40%;">
<div style="margin-top: 0px;">
@Html.EJS().NumericTextBox("labelWidth").Change("widthChange").Value(34).Min(1).Width("120").Step(1).Render()
</div>
</td>
</tr>
</tbody>
</table>
</div>
@*custom code start*@
<style>
#control-container {
padding: 0px !important;
}
</style>
@*custom code end*@
<script>
var labelRender = function (args) {
var selectedTheme = themeName ? themeName : 'Material';
if (selectedTheme && selectedTheme.indexOf('fabric') > -1) {
args.fill = fabricColors[args.point.index % 10];
}
else if (selectedTheme === 'material') {
args.fill = materialColors[args.point.index % 10];
}
else {
args.fill = bootstrapColors[args.point.index % 10];
}
};
@*custom code start*@
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');
};
@*custom code end*@
var valueChange = function () {
var chart = document.getElementById('container').ej2_instances[0];
var selmode = document.getElementById('selmode').ej2_instances[0];
chart.primaryXAxis.labelIntersectAction = selmode.value;
chart.series[0].animation.enable = false;
chart.refresh();
}
var edgeModeChange = function () {
var chart = document.getElementById('container').ej2_instances[0];
var edgemode = document.getElementById('edgemode').ej2_instances[0];
chart.primaryXAxis.edgeLabelPlacement = edgemode.value;
chart.series[0].animation.enable = false;
chart.dataBind();
}
var positionChange = function () {
var chart = document.getElementById('container').ej2_instances[0];
var position = document.getElementById('position').ej2_instances[0];
chart.primaryXAxis.labelPosition = position.value;
chart.series[0].animation.enable = false;
chart.refresh();
}
document.getElementById('Trim').onchange = function () {
var chart = document.getElementById('container').ej2_instances[0];
var element = (document.getElementById('Trim'));
chart.primaryXAxis.enableTrim = element.checked;
chart.refresh();
};
var widthChange= function () {
var chart = document.getElementById("container").ej2_instances[0];
var width = document.getElementById("labelWidth").ej2_instances[0];
chart.series[0].animation.enable = false;
chart.primaryXAxis.maximumLabelWidth = width.value;
chart.series[0].animation.enable = false;
chart.refresh();
}
</script>
}
@*custom code start*@
@section Meta{
<meta name="description" content="This example demonstrates the Smart Axis Labels in ASP.NET MVC Chart control. Explore here for more details."/>
}
@*custom code end*@
@section ActionDescription{
<p>
Labels in an axis can be placed smartly when it intersects with each other. Intersect action and edge label placement can be changed by using property panel.
</p>
}
@section Description{
<p>
In this example, you can see how to arrange the axis labels and how to trim the axis label smartly. When the Axis labels overlap with each other based on
the chart dimensions and label size, you can use the <code>labelIntersectAction</code> property of the axis
to avoid overlapping.
</p>
<p>
Chart supports the following by which can be set using <code>labelIntersectAction</code> property.
</p>
<ul>
<li><code>Hide</code> - Hide the label when it intersect.</li>
<li><code>Trim</code> - Trim the label when it intersect.</li>
<li><code>Wrap</code> - Wrap the label when it intersect.</li>
<li><code>MultipleRows</code> - Arrange the label in multiple row when it intersect.</li>
<li><code>Rotate45</code> - Rotate the label to 45 degree when it intersect.</li>
<li><code>Rotate90</code> - Rotate the label to 90 degree when it intersect.</li>
<li><code>None</code> - Shows all the labels.</li>
</ul>
<br>
<p>
Chart supports three types of edge labels placement which can be set using <code>edgeLabelPlacement</code> property.
</p>
<ul>
<li><code>None</code> - No action will be performed.</li>
<li><code>Hide</code> - Edge label will be hidden .</li>
<li><code>Shift</code> - Shifts the edge labels.</li>
</ul>
<p>
More information on the smart axis labels can be found in this
<a target="_blank" href="http://ej2.syncfusion.com/documentation/chart/api-axis.html#valuetype-valuetype">documentation section</a>.
</p>
}
@section Title{
<title>ASP.NET MVC Chart Smart Axis Labels Example - Syncfusion Demos </title>
}
@section Header{
<h1 class='sb-sample-text'>Example of Smart Axis Labels in ASP.NET MVC Chart Control</h1>
}