Chart's Scale Breaks - Custom Property
- 3 minutes to read
This extension enables or disables scale breaks for the Chart dashboard item.
In the extension code you can find how to:
- Add a custom Boolean property for a specific dashboard item (Chart).
- Integrate a Scale breaks (Custom) section into the Options menu with the CheckBox widget as an editor.
Tip
Examples on GitHub:
Every extension that provides a custom property can be divided to the following parts:
Model
The model is a CustomPropertyMetadata object that contains the property name, type, and the default value. It also specifies on which level the property is created (a dashboard, dashboard item or data item container). Use the Model.registerCustomProperty property to register the custom property definition.
var ChartScaleBreaksExtension = (function() {
var Model = DevExpress.Dashboard.Model;
// 1. Model
var autoScaleBreaksProperty = {
ownerType: Model.ChartItem,
propertyName: 'ScaleBreaks',
defaultValue: false,
valueType: 'boolean'
};
Model.registerCustomProperty(autoScaleBreaksProperty);
return ChartScaleBreaksExtension;
}());
Viewer
In this part, you modify the viewer according to the saved custom property value. You can use the client methods and events to change the displayed elements. In this example, you change the Chart widget’s valueAxis.autoBreaksEnabled according to the custom property value.
var ChartScaleBreaksExtension = (function() {
var Model = DevExpress.Dashboard.Model;
// 2. Viewer
function onItemWidgetOptionsPrepared(args) {
var scaleBreaks = args.dashboardItem.customProperties.getValue(autoScaleBreaksProperty.propertyName);
if (scaleBreaks) {
var valueAxisOptions = args.options["valueAxis"];
if (valueAxisOptions && valueAxisOptions[0]) {
valueAxisOptions[0].autoBreaksEnabled = true;
}
}
};
return ChartScaleBreaksExtension;
}());
Designer
This part contains designer settings. Add editors and control elements to configure and change the custom property’s values in the UI. This part is not required if you use the extension in Viewer mode or do not want to let users edit a custom property’s value. For this custom property, integrate a Scale breaks (Custom) section in the Options menu with the CheckBox widget as an editor.
var ChartScaleBreaksExtension = (function() {
var Model = DevExpress.Dashboard.Model;
// 3. Designer
function onCustomizeSections(args) {
args.addSection({
title: "Scale breaks (Custom)",
items: [
{
dataField: autoScaleBreaksProperty.propertyName,
editorType: "dxCheckBox",
label: {
visible: false
},
editorOptions: {
text: "Enable Auto Scale breaks"
}
}
]
});
};
return ChartScaleBreaksExtension;
}());
Event Subscription
This part contains event subscriptions. In this example, it is the ViewerApiExtensionOptions.onItemWidgetOptionsPrepared and OptionsPanelExtensionOptions.onCustomizeSections events.
var ChartScaleBreaksExtension = (function() {
// 4. Event Subscription
function ChartScaleBreaksExtension(dashboardControl) {
this.name = "ScaleBreaks",
this.start = function () {
var viewerApiExtension = dashboardControl.findExtension('viewerApi');
if (viewerApiExtension) {
viewerApiExtension.on('itemWidgetOptionsPrepared', onItemWidgetOptionsPrepared);
}
var optionsPanelExtension = dashboardControl.findExtension("itemOptionsPanel");
if (optionsPanelExtension) {
optionsPanelExtension.on('customizeSections', onCustomizeSections);
}
},
this.stop = function () {
var viewerApiExtension = dashboardControl.findExtension('viewerApi');
if (viewerApiExtension) {
viewerApiExtension.off('itemWidgetOptionsPrepared', onItemWidgetOptionsPrepared);
}
var optionsPanelExtension = dashboardControl.findExtension("itemOptionsPanel");
if (optionsPanelExtension) {
optionsPanelExtension.off('customizeSections', onCustomizeSections);
}
}
}
return ChartScaleBreaksExtension;
}());