[]
Several Wijmo controls have properties that take enumeration values.
For example, the FlexChart's chartType property takes wijmo.chart.ChartType values.
The recommended way to set enumeration properties is as follows:
import { ChartType } from '@mescius/wijmo.chart';
// setting the value of an enumeration property
chart.chartType = ChartType.Line;
The following alternatives are also valid and produce the same result:
// wijmo.chart.ChartType.Line has value 3:
chart.chartType = 3;
// enumerations are automatically parsed
chart.chartType = 'Line';
Getting the property will return 3 in all cases. If you want to get the value as a string (to show in the UI for example), you can do it as follows:
// getting the enumerated value as a number
console.log(chart.chartType); // outputs "3"
// getting the enumerated value as a string
console.log(ChartType\[chart.chartType\]); // outputs "Line"
You can use the enumeration classes to convert between strings and the corresponding numbers by indexing. For example:
// convert enumeration value to string
console.log(ChartType\[3\]); // outputs "Line"
console.log(ChartType\[1000\]); // outputs "null"
// convert string to enumeration value
console.log(ChartType\['Line'\]); // outputs "3"
console.log(ChartType\['NoSuchValue'\]); // outputs "null"
The .NET, Enum class provides methods called GetNames and GetValues that return the names and values defined by any enumeration.
The code below shows how you could implement similar methods to get the names and values defined by TypeScript enumerations (as used in Wijmo):
import { DataType } from '@mescius/wijmo';
// get the names defined by an enumeration
function getEnumNames(enumClass) {
var names = \[\];
for (var key in enumClass) {
var val = parseInt(key);
if (isNaN(val)) names.push(key);
}
return names;
}
// get the values defined by an enumeration
function getEnumValues(enumClass) {
var values = \[\];
for (var key in enumClass) {
var val = parseInt(key);
if (!isNaN(val)) values.push(val);
}
return values;
}
// sample usage:
var nn = getEnumNames(DataType); // returns \[ 'Object', 'String', 'Number', 'Boolean', 'Array' \]
var vv = getEnumValues(DataType); // returns \[ 0, 1, 2, 3, 4 \]