Defaults Section

Overview

In many situations, several charts may have similar settings for the various elements they contain; these elements may be rather complex, and XML that configures them subsequently may be rather large.

To avoid duplicating similar settings and to make the XML configuration file smaller, you can take advantage of the Defaults Section, which is shown on the XML listing below:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <settings>
04     <defaults>
05       <chart />
06       <label />
07     </defaults>
08   </settings>
09 </stock>
01{
02  settings: {
03    defaults: {
04      chart: {},
05      label: {}
06    }
07  }
08}

In this section, you will learn how to use the defaults section for different elements; please note that any time you define any settings in an element - these settings override the defaults.

to top

Default Chart Settings

You can define common chart settings for all charts displayable by the component. For that purpose, you would need to use the <chart> subnode of the <defaults> node. Here is a sample XML that shows such node:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <settings>
04     <defaults>
05       <chart />
06     </defaults>
07   </settings>
08 </stock>
01{
02  settings: {
03    defaults: {
04      chart: {}
05    }
06  }
07}

Entire Chart

For example, you may want to turn off the legend background in all charts. For that purpose, simply make necessary settings in the defaults node, just as if you were to do that in the chart node. Here is a sample XML with such settings:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <settings>
04     <defaults>
05       <chart>
06         <legend>
07           <background enabled="false" />
08         </legend>
09       </chart>
10     </defaults>
11   </settings>
12 </stock>
01{
02  settings: {
03    defaults: {
04      chart: {
05        legend: {
06          background: {
07            enabled: false
08          }
09        }
10      }
11    }
12  }
13}

Besides the legend, you can define all other elements too. Defining something in the defaults section is the same as defining the same in all charts at once. The example below demonstrates the definition of a chart background, axes settings, legend settings and so on in the defaults section and shows two charts with those definitions applied. Take a note that the value axes have different formats (the lower chart uses scaling) although the labels format is defined in the defaults; that is so because the lower chart defines its own label format, which overrides the default one:

Live Sample:  Defaults for Entire Chart

To configure your charts properly, please refer to:

to top

Default Series Settings

Series settings can be very large, as they define what the lines, area and bars should look like; they contain tooltip configuration options and much more. Besides that, sometimes one chart may have only a line type series, while the other may also have bars; you may want to keep them both in one place in XML - to make it easier to modify them. All that can be done in the series section defaults.

Here is a sample XML that defines all those line type series:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <settings>
04     <defaults>
05       <chart>
06         <series_settings_defaults>
07           <line_series thickness="3" />
08         </series_settings_defaults>
09       </chart>
10     </defaults>
11   </settings>
12 </stock>
01{
02  settings: {
03    defaults: {
04      chart: {
05        seriesSettingsDefaults: {
06          lineSeries: {
07            thickness: 3
08          }
09        }
10      }
11    }
12  }
13}

The Live Sample below shows how even very complex tooltip settings can be applied to all line charts at once:

Live Sample:  Defaults Section - Series Settings Defaults

To configure series properly, please refer to:

to top

Default Technical Indicator Settings

Technical indicators settings are pretty similar to series settings, and their defaults are defined pretty much the same way.

Here is a sample XML that defines line thickness for all SMA indicators:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <settings>
04     <defaults>
05       <chart>
06         <technical_indicators_defaults>
07           <sma_indicator>
08             <series type="Spline" color="DarkRed">
09               <line_series thickness="2" />
10             </series>
11           </sma_indicator>
12         </technical_indicators_defaults>
13       </chart>
14     </defaults>
15   </settings>
16 </stock>
01{
02  settings: {
03    defaults: {
04      chart: {
05        technicalIndicatorsDefaults: {
06          smaIndicator: {
07            series: {
08              type: "Spline",
09              color: "DarkRed",
10              lineSeries: {
11                thickness: 2
12              }
13            }
14          }
15        }
16      }
17    }
18  }
19}

The Live Sample below demonstrates setting the default name, period, and color for all SMA indicators to be shown; the only things defined in the charts are data provider and type:

Live Sample:  Defaults Section - Technical Indicators Settings Defaults

To configure technical indicators properly, please refer to:

to top

Default Custom Label Settings

If your chart uses a lot of extra labels, and you want to give them all a similar look, you can take advantage of the defaults set for the labels section.

This sample XML syntax defines complex background and font settings for all labels:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <settings>
04     <defaults>
05       <label>
06         <font family="Tahoma" color="#2654AA" size="12" bold="true" />
07         <background>
08           <fill type="Gradient">
09             <gradient angle="90">
10               <keys>
11                 <key color="#FEFEFE" />
12                 <key color="#F1F1F1" />
13               </keys>
14             </gradient>
15           </fill>
16           <border color="#BDBDBD" />
17           <corners type="Rounded" all="4" />
18           <inside_margin left="9" top="3" right="9" bottom="3" />
19         </background>
20       </label>
21     </defaults>
22   </settings>
23 </stock>
01{
02  settings: {
03    defaults: {
04      label: {
05        font: {
06          family: "Tahoma",
07          color: "#2654AA",
08          size: 12,
09          bold: true
10        },
11        background: {
12          fill: {
13            type: "Gradient",
14            gradient: {
15              angle: 90,
16              keys: [
17                {
18                  color: "#FEFEFE"
19                },
20                {
21                  color: "#F1F1F1"
22                }
23              ]
24            }
25          },
26          border: {
27            color: "#BDBDBD"
28          },
29          corners: {
30            type: "Rounded",
31            all: 4
32          },
33          insideMargin: {
34            left: 9,
35            top: 3,
36            right: 9,
37            bottom: 3
38          }
39        }
40      }
41    }
42  }
43}

And the Live Sample below demonstrates how these settings work:

Live Sample:  Defaults Section - Inividual Charts Labels Settings Defaults

To configure labels properly, please refer to:

to top