# FlexChart 101

This page shows how to get started with Wijmo's FlexChart control.

## Getting Started

Steps for getting started with the FlexChart in AngularJS applications:

1. Add references to AngularJS, Wijmo, and Wijmo's AngularJS directives.
2. Include the Wijmo directives in the app module:
   `var app = angular.module('app', ['wj']);`
3. Add a controller to provide data and logic.
4. Add a FlexChart to the page and bind it to the data.
5. Add an appropriate CSS to customize the chart's appearance.

<html> <head> <link rel="stylesheet" href="css/bootstrap.css"/> <link rel="stylesheet" href="css/wijmo.css"/> <link href="css/app.css" rel="stylesheet"/> <script src="scripts/angular.js"></script> <script src="scripts/wijmo.js"></script> <script src="scripts/wijmo.chart.js"></script> <script src="scripts/wijmo.angular.js"></script> <script src="scripts/app.js"></script> </head> <body ng-app="app" ng-controller="appCtrl"> <!-- this is the chart --> <wj-flex-chart items-source="data" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales"> </wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"> </wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"> </wj-flex-chart-series> </wj-flex-chart> </body> </html>
// declare app module var app = angular.module('app', ['wj']); // app controller provides data app.controller('appCtrl', function appCtrl($scope) { // generate some random data var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // add data array to scope $scope.data = data; });
/* set default chart style */ .wj-flexchart { height: 400px; background-color: white; box-shadow: 4px 4px 10px 0px rgba(50, 50, 50, 0.75); padding: 8px; margin-bottom: 12px; }

#### Result (live):

## Chart Types

The FlexChart control has the following three properties, which allow you to customize the chart type:

1. chartType: Selects the default chart type to be used for all series objects. Individual series objects can override this.
2. stacking: Determines whether series objects are plotted independently, stacked, or stacked so their sum is 100%.
3. rotated: Flips the X and Y axes so X becomes vertical and Y horizontal.

The example below allows you to see what happens when you change these properties:

<wj-flex-chart items-source="data" chart-type="{{chartProps.chartType}}" stacking="{{chartProps.stacking}}" rotated="{{chartProps.rotated}}" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales"> </wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"> </wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"> </wj-flex-chart-series> </wj-flex-chart> <wj-menu value="chartProps.chartType" header="Chart Type" > <wj-menu-item value="0">Column</wj-menu-item> <wj-menu-item value="1">Bar</wj-menu-item> <wj-menu-item value="2">Scatter</wj-menu-item> <wj-menu-item value="3">Line</wj-menu-item> <wj-menu-item value="4">LineSymbols</wj-menu-item> <wj-menu-item value="5">Area</wj-menu-item> <wj-menu-item value="9">Spline</wj-menu-item> <wj-menu-item value="10">SplineSymbols</wj-menu-item> <wj-menu-item value="11">SplineArea</wj-menu-item> </wj-menu> <wj-menu value="chartProps.stacking" header="Stacking" > <wj-menu-item value="0">None</wj-menu-item> <wj-menu-item value="1">Stacked</wj-menu-item> <wj-menu-item value="2">Stacked 100%</wj-menu-item> </wj-menu> <wj-menu value="chartProps.rotated" header="Rotated" > <wj-menu-item value="false">False</wj-menu-item> <wj-menu-item value="true">True</wj-menu-item> </wj-menu>
// add chart properties to scope $scope.chartProps = { chartType: wijmo.chart.ChartType.Column, stacking: wijmo.chart.Stacking.None, rotated: false };

#### Result (live):

Column Bar Scatter Line LineSymbols Area Spline SplineSymbols SplineArea None Stacked Stacked 100% False True

## Range Bar/Column

The example below shows how to create and a range bar/column chart:

<wj-flex-chart control="rangeChart" items-source="rangeData" chart-type="{{chartProps.rangeChartType}}" binding-x="country"> <wj-flex-chart-series binding="{{chartProps.rangeChartBinding}}"> </wj-flex-chart-series> </wj-flex-chart> <wj-menu value="chartProps.rangeChartType" header="Chart Type" > <wj-menu-item value="0">Column</wj-menu-item> <wj-menu-item value="1">Bar</wj-menu-item> </wj-menu> <wj-menu value="chartProps.rangeChartBinding" header="Data Type" > <wj-menu-item value="'num1,num2'">Number</wj-menu-item> <wj-menu-item value="'date1,date2'">Date</wj-menu-item> </wj-menu>
// add chart properties to scope $scope.rangeData = rangeData; $scope.chartProps = { rangeChartType: wijmo.chart.ChartType.Column, rangeChartBinding: 'num1,num2' }; $scope.$watch('rangeChart', function () { var rangeChart = $scope.rangeChart; if (rangeChart != null) { rangeChart.tooltip.content = function (ht) { var str = ht.x + ':
'; var dataTypes = $scope.chartProps.rangeChartBinding.split(','); var min = Math.min(ht.item[dataTypes[0]], ht.item[dataTypes[1]]); var max = Math.max(ht.item[dataTypes[0]], ht.item[dataTypes[1]]); if (wijmo.isDate(ht.item[dataTypes[0]])) { str += (new Date(min)).toLocaleDateString() + ' - ' + (new Date(max)).toLocaleDateString(); } else { str += Math.round(min) + ' - ' + Math.round(max); } return str; }; } });

#### Result (live):

Column Bar Number Date

## Funnel Charts

The example below shows how to create and customize a Funnel Chart:

<wj-flex-chart control="funnelChart" items-source="funnelData" chart-type="Funnel" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> </wj-flex-chart> <dl class="dl-horizontal"> <dt>Neck Width</dt> <dd> <div id="funnelNeckWidth"></div> <wj-input-number control="inputNeckWidth" value="neckWidth" min="0" max="1" step=".1"> </wj-input-number> </dd> </dl> <dl class="dl-horizontal"> <dt>Neck Height</dt> <dd> <div id="funnelNeckHeight"></div> <wj-input-number control="inputNeckHeight" value="neckHeight" min="0" max="1" step=".1"> </wj-input-number> </dd> </dl> <dl class="dl-horizontal"> <dt></dt> <dd> <wj-menu header="Funnel Type: <b>{{ funnelType }}</b>" item-clicked="funnelTypeChanged(s, e)"> <wj-menu-item value="'default'">Default</wj-menu-item> <wj-menu-item value="'rectangle'">Rectangle</wj-menu-item> </wj-menu> </dd> </dl>
$scope.funnelChart = null; $scope.inputNeckWidth = null; $scope.inputNeckHeight = null; $scope.neckWidth = 0.2; $scope.neckHeight = 0.2; $scope.funnelType = 'default'; $scope.$watch('funnelChart', function () { var funnelChart = $scope.funnelChart; if (funnelChart != null) { funnelChart.options = { funnel: { neckWidth: 0.2, neckHeight: 0.2, type: 'default' } }; funnelChart.dataLabel.content = '{y}'; } }); $scope.$watch('neckWidth', function () { var neckWidth = $scope.inputNeckWidth, val = $scope.neckWidth; if (neckWidth != null) { if (val < neckWidth.min || val > neckWidth.max) { return; } $scope.funnelChart.options.funnel.neckWidth = val; $scope.funnelChart.refresh(true); } }); $scope.$watch('neckHeight', function () { var neckHeight = $scope.inputNeckHeight, val = $scope.neckHeight; if (neckHeight != null) { if (val < neckHeight.min || val > neckHeight.max) { return; } $scope.funnelChart.options.funnel.neckHeight = val; $scope.funnelChart.refresh(true); } }); $scope.funnelTypeChanged = function (sender) { $scope.funnelChart.options.funnel.type = sender.selectedValue; $scope.funnelChart.refresh(true); };

#### Result (live):

Neck Width

Neck Height

  Default Rectangle

## Mixed Chart Types

You can use different chart types for each chart series by setting the chartType property on the series itself. This overrides the chart's default chart type.

In the example below, the chart's chartType property is set to Column, but the Downloads series overrides it to use the LineAndSymbol chart type:

<wj-flex-chart items-source="data" chart-type="Column" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads" chart-type="LineSymbols"></wj-flex-chart-series> </wj-flex-chart>

#### Result (live):

## Legend and Titles

Use legend's properties to customize the appearance of the chart legend, and the header, footer, and axis title properties to add titles to your charts.

You can style the legend and titles using CSS. The CSS tab below shows the rules used to customize the appearance of the legend and titles. Notice that these are SVG elements, so you have to use CSS attributes such as "fill" instead of "color."

<wj-flex-chart items-source="data" binding-x="country" header="{{chartProps.header}}" footer="{{chartProps.footer}}"> <wj-flex-chart-legend position="{{chartProps.legendPosition}}"> </wj-flex-chart-legend> <wj-flex-chart-axis wj-property="axisX" title="{{chartProps.titleX}}"> </wj-flex-chart-axis> <wj-flex-chart-axis wj-property="axisY" title="{{chartProps.titleY}}"> </wj-flex-chart-axis> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"></wj-flex-chart-series> </wj-flex-chart> <dl class="dl-horizontal"> <dt>Header</dt><dd><input ng-model="chartProps.header" class="form-control"/></dd> <dt>Footer</dt><dd><input ng-model="chartProps.footer" class="form-control"/></dd> <dt>X-Axis Title</dt><dd><input ng-model="chartProps.titleX" class="form-control"/></dd> <dt>Y-Axis Title</dt><dd><input ng-model="chartProps.titleY" class="form-control"/></dd> <dt></dt> <dd> <wj-menu value="chartProps.legendPosition" header="Legend" > <wj-menu-item value="0">None</wj-menu-item> <wj-menu-item value="1">Left</wj-menu-item> <wj-menu-item value="2">Top</wj-menu-item> <wj-menu-item value="3">Right</wj-menu-item> <wj-menu-item value="4">Bottom</wj-menu-item> </wj-menu> </dd> </dl>
// add chart properties to scope $scope.chartProps = { chartType: wijmo.chart.ChartType.Column, legendPosition: wijmo.chart.Position.Right, stacking: wijmo.chart.Stacking.None, rotated: false, header: 'Sample Chart', footer: 'copyright (c) ComponentOne', titleX: 'country', titleY: 'amount' };
.wj-flexchart .wj-title { font-weight: bold; } .wj-flexchart .wj-header .wj-title { font-size: 18pt; fill: #80044d; } .wj-flexchart .wj-footer .wj-title { fill: #80044d; } .wj-flexchart .wj-axis-x .wj-title, .wj-flexchart .wj-axis-y .wj-title { font-style: italic; }

#### Result (live):

Header
Footer
X-Axis Title
Y-Axis Title
  None Left Top Right Bottom

## Tooltips

The FlexChart has built-in support for tooltips. By default, the control displays tooltips when the user touches or hovers the mouse on a data point.

The tooltip content is generated using a template that may contain the following parameters:

- seriesName: The name of the series that contains the chart element.
- pointIndex: The index of the chart element within the series.
- x: The x value of the chart element.
- y: The y value of the chart element.

By default, the tooltip template is set to `<b>{seriesName}</b><br/>{x} {y}`, and you can see how that works in the charts above. In this example, we set the tooltip template to `<b>{seriesName}</b> <img src='resources/{x}.png'/><br/>{y}`, which replaces the country name with the country's flag.

You can disable the chart tooltips by setting the template to an empty string.

<wj-flex-chart items-source="data" tooltip-content="<img src='resources/{x}.png'/> <b>{seriesName}</b><br/>{y}" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"></wj-flex-chart-series> </wj-flex-chart>

#### Result (live):

## Styling Series

The FlexChart automatically picks colors for each series based on a default palette, which you can override by setting the palette property. But you can also override the default settings by setting the style property of any series to an object that specifies SVG styling attributes, including fill, stroke, strokeThickness, and so on.

The Series.style property is an exception to the general rule that all styling in Wijmo is done through CSS. The exception reflects the fact that many charts have dynamic series, which would be impossible to style in advance. For example, a stock chart may show series selected by the user while running the application.

The chart in this example uses the style and symbolStyle properties to select style attributes for each series:

<wj-flex-chart items-source="data" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales" ng-attr-style="{fill:'green', stroke:'darkgreen', 'stroke-width': '1'}"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses" ng-attr-style="{fill:'red', stroke:'darkred', 'stroke-width': '1'}"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads" chart-type="'LineSymbols'" ng-attr-style="{ stroke:'orange', 'stroke-width': '5'}" ng-attr-symbol-style="{fill:'gold', stroke:'gold' }"></wj-flex-chart-series> </wj-flex-chart>

#### Result (live):

## Customizing Axes

Use axis properties to customize the chart's axes, including ranges (minimum and maximum), label format, tickmark spacing, and gridlines.

The Axis class has boolean properties that allow you to turn features on or off (axisLine, labels, majorTickMarks, and majorGrid). You can style the appearance of the features that are turned on using CSS.

<wj-flex-chart items-source="data" binding-x="country"> <wj-flex-chart-axis wj-property="axisX" axis-line="true" major-grid="true"> </wj-flex-chart-axis> <wj-flex-chart-axis wj-property="axisY" format="c0" max="10000" major-unit="2000" axis-line="true" major-grid="true"> </wj-flex-chart-axis> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> </wj-flex-chart>

#### Result (live):

## Theming

The appearance of the FlexChart is defined in CSS. In addition to the default theme, we include about a dozen professionally designed themes that customize the appearance of all Wijmo controls to achieve a consistent attractive look.

To customize the appearance of the chart, inspect the elements you want to style and create some CSS rules that apply to those elements.

For example, if you right-click one of the labels on the X axis in IE or Chrome, you will see that it is an element with the "wj-label" class, that is contained in an element with the "wj-axis-x" class, which is contained in the the top-level control element that has the "wj-flexchart" class. The first CSS rule in this example uses this information to customize the X labels. The rule selector adds the additional requirement that the parent element must have, the "wj-flexchart" and the "custom-flex-chart" classes. Without this, the rule would apply to all charts on the page.

<wj-flex-chart class="custom-flex-chart" items-source="data" binding-x="country"> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"></wj-flex-chart-series> </wj-flex-chart>
/* custom chart theme */ .custom-flex-chart.wj-flexchart .wj-axis-x .wj-label { font-family: Courier New, Courier, monospace; font-weight: bold; } .custom-flex-chart.wj-flexchart .wj-legend .wj-label { font-family: Courier New, Courier, monospace; font-weight: bold; } .custom-flex-chart.wj-flexchart .wj-legend > rect { fill: #f8f8f8; stroke: #c0c0c0; } .custom-flex-chart.wj-flexchart .wj-plot-area > rect { fill: #f8f8f8; stroke: #c0c0c0; }

#### Result (live):

## Selection Modes

The FlexChart allows you to select series or data points by clicking or touching them. Use the selectionMode property to specify whether you want to allow selection by series, by data point, or no selection at all (selection is off by default.)

Setting the selectionMode property to Series or Point causes the FlexChart to update the Selection property when the user clicks the mouse, and to apply the "wj-state-selected" class to selected chart elements.

The Selection property returns the currently selected series. To get the currently selected data point, get the currently selected item within the selected series using the Series.collectionView.currentItem property, as shown in the example.

<wj-flex-chart items-source="data" binding-x="country" tooltip-content="" chart-type="{{chartProps.chartType}}" selection-mode="{{chartProps.selectionMode}}" selection="chartProps.selection"> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"></wj-flex-chart-series> </wj-flex-chart> <div ng-hide="chartProps.selectionMode == 0 || chartProps.selection == null"> <h4> Current Selection</h4> <p> Series: <b>{​{chartProps.selection.name}}</b></p> <dl class="dl-horizontal" ng-hide="chartProps.selectionMode != 2 || chartProps.selection.collectionView.currentItem == null"> <dt>Country</dt><dd>{​{chartProps.selection.collectionView.currentItem.country}}</dd> <dt>Sales</dt><dd>{​{chartProps.selection.collectionView.currentItem.sales | number:2}}</dd> <dt>Expenses</dt><dd>{​{chartProps.selection.collectionView.currentItem.expenses | number:2}}</dd> <dt>Downloads</dt><dd>{​{chartProps.selection.collectionView.currentItem.downloads | number:0}}</dd> </dl> </div>
// add chart properties to scope $scope.chartProps = { chartType: wijmo.chart.ChartType.Column, stacking: wijmo.chart.Stacking.None, legendPosition: wijmo.chart.Position.Right, rotated: false, header: 'Sample Chart', footer: 'copyright (c) ComponentOne', titleX: 'country', titleY: 'amount', selectionMode: wijmo.chart.SelectionMode.Series, selection: null };

#### Result (live):

None Series Point Column Bar Scatter Line LineSymbols Area Spline SplineSymbols SplineArea

#### Current Selection

Series: {{chartProps.selection.name}}

Country
  {{chartProps.selection.collectionView.currentItem.country}}
Sales
  {{chartProps.selection.collectionView.currentItem.sales | number:2}}
Expenses
  {{chartProps.selection.collectionView.currentItem.expenses | number:2}}
Downloads
  {{chartProps.selection.collectionView.currentItem.downloads | number:0}}

## Toggle Series

The Series class has a visibility property that allows you to determine whether a series should be shown in the chart and in the legend, or only in the legend, or completely hidden.

This sample shows how you can use the visibility property to toggle the visibility of a series using the following two ways:

1. Clicking the legend entries:
   The chart directive sets the chart's legendToggle property to true, which toggles the visibility property of a series when its legend entry is clicked.
2. Using checkboxes:
   The page uses Angular directives to bind input controls directly to the visibility property of each series.

<wj-flex-chart items-source="data" legend-toggle="true" control="toggleChart"> <wj-flex-chart-series name="Sales" binding="sales"></wj-flex-chart-series> <wj-flex-chart-series name="Expenses" binding="expenses"></wj-flex-chart-series> <wj-flex-chart-series name="Downloads" binding="downloads"></wj-flex-chart-series> </wj-flex-chart> Sales <input type="checkbox" ng-model="toggleChart.series[0].visibility" ng-true-value="0" ng-false-value="2" ng-checked="true"/><br /> Expenses <input type="checkbox" ng-model="toggleChart.series[1].visibility" ng-true-value="0" ng-false-value="2" ng-checked="true"/><br /> Downloads <input type="checkbox" ng-model="toggleChart.series[2].visibility" ng-true-value="0" ng-false-value="2" ng-checked="true"/>
// toggle series visibility when user clicks on the legend // (note: this code is in the chart directive) control.hostElement.addEventListener('click', function (e) { if (scope.seriesToggle == true) { var ht = control.hitTest(e); if (ht && ht.chartElement == wijmo.chart.ChartElement.Legend && ht.series) { if (ht.series.visibility == wijmo.chart.SeriesVisibility.Legend) { ht.series.visibility = wijmo.chart.SeriesVisibility.Visible; } else { ht.series.visibility = wijmo.chart.SeriesVisibility.Legend; } } } });

#### Result (live):

Sales
Expenses
Downloads

## Gradient Colors

The FlexChart supports gradient colors.

The gradient descriptor is an expression formatted as follows: `<type>(<coords>)<colors>[:<offset>[:<opacity>]][-<colors>[:<offset>[:<opacity>]]]-<colors>[:<offset>[:<opacity>]]`. The `<type>` can be either linear or radial. The uppercase `L` or `R` letters indicate absolute coordinates offset from the SVG surface. Lowercase `l` or `r` letters indicate coordinates calculated relative to the element to which the gradient is applied. Coordinates specify a linear gradient vector as `x1`, `y1`, `x2`, `y2`, or a radial gradient as `cx`, `cy`, `r` and optional `fx`, `fy`, `fr` specifying a focal point away from the center of the circle. Specify `<colors>` as a list of dash-separated CSS color values. Each color may be followed by a custom offset and opacity value, separated with a colon character.

Linear gradient format example:

`'l(0,0,1,0)#ff0000-#00ff00-#0000ff'`, `'L(0,0,300,300)#ff0000:0.2:0.2-00ff00:0.8'`

Radial gradient format example:

`'r(0.5,0.5,1)#ff0000-#0000ff'`, `'R(100,100,100,200,200,200)#ff0000-#0000ff'`

### Basic

Select from the predefined gradient colors to see the different appearances.

<wj-flex-chart items-source="data" binding-x="country" control="gradientBasicChart"> <wj-flex-chart-series binding="sales" ng-attr-style="chartProps.gradientPredefinedColor"></wj-flex-chart-series> </wj-flex-chart> <dl class="dl-horizontal"> <wj-menu value="chartProps.gradientPredefinedColor" header="Gradient Color"> <wj-menu-item value="{fill:'l(0,0,1,0)#89f7fe-#66a6ff'}">Light Blue - l(0, 0, 1, 0)#89f7fe-#66a6ff</wj-menu-item> <wj-menu-item value="{fill:'l(0,0,0,1)#13547a-#80d0c7'}">Aqua - l(0, 0, 0, 1)#13547a-#80d0c7</wj-menu-item> <wj-menu-item value="{fill:'l(0,0,1,1)#ff0844-#ffb199'}">Red - l(0, 0, 1, 1)#ff0844-#ffb199</wj-menu-item> <wj-menu-item value="{fill:'l(0,0,1,0)#b224ef-#7579ff-#b224ef'}">Purple - l(0, 0, 1, 0)#b224ef-#7579ff-#b224ef</wj-menu-item> <wj-menu-item value="{fill:'r(0.5,0.5,0.7)#cc208e-#6713d2'}">Plum - r(0.5,0.5,0.7)#cc208e-#6713d2</wj-menu-item> <wj-menu-item value="{fill:'l(0,0,1,0)#30cfd0-#330867'}">Deep Blue - l(0, 0, 1, 0)#30cfd0-#330867</wj-menu-item> <wj-menu-item value="{fill:'l(0,0,0,1)#e27f00-#ae1a73'}">Orange - l(0, 0, 0, 1)#e27f00-#ae1a73</wj-menu-item> <wj-menu-item value="{fill:'l(0,0,1,1)#abd800-#5c7e00'}">Green - l(0, 0, 1, 1)#abd800-#5c7e00</wj-menu-item> </wj-menu> </dl>
// add chart properties to scope $scope.chartProps = { gradientPredefinedColor: { fill:'l(0,0,1,0)#89f7fe-#66a6ff' } };

#### Result (live):

Light Blue - l(0, 0, 1, 0)#89f7fe-#66a6ff Aqua - l(0, 0, 0, 1)#13547a-#80d0c7 Red - l(0, 0, 1, 1)#ff0844-#ffb199 Purple - l(0, 0, 1, 0)#b224ef-#7579ff-#b224ef Plum - r(0.5,0.5,0.7)#cc208e-#6713d2 Deep Blue - l(0, 0, 1, 0)#30cfd0-#330867 Orange - l(0, 0, 0, 1)#e27f00-#ae1a73 Green - l(0, 0, 1, 1)#abd800-#5c7e00

### Advanced

Set multiple options to customize gradient color.

<wj-flex-chart items-source="data" control="gradientChart"> <wj-flex-chart-series binding="sales"></wj-flex-chart-series> </wj-flex-chart> <dl class="dl-horizontal"> <dt>Generated fill string:</dt> <dd> <label>{{ chartProps.gradientFill }}</label> </dd> <dt></dt> <dd> <wj-menu value="chartProps.gradientType" header="Type"> <wj-menu-item value="'l'">Linear</wj-menu-item> <wj-menu-item value="'r'">Radial</wj-menu-item> </wj-menu> </dd> <dt ng-show="chartProps.gradientType === 'l'"></dt> <dd ng-show="chartProps.gradientType === 'l'"> <wj-menu is-visible="false" value="chartProps.gradientDirection" header="Direction"> <wj-menu-item value="'horizontal'">Horizontal</wj-menu-item> <wj-menu-item value="'vertical'">Vertical</wj-menu-item> </wj-menu> </dd> <dt>Start Color:</dt> <dd><wj-input-color value="chartProps.startColor"></wj-input-color></dd> <dt>Start Offset:</dt> <dd> <wj-input-number control="inputStartOffset" value="chartProps.startOffset" min="0" max="1" step=".1"> </wj-input-number> </dd> <dt>Start Opacity:</dt> <dd> <wj-input-number control="inputStartOpacity" value="chartProps.startOpacity" min="0" max="1" step=".1"> </wj-input-number> </dd> <dt>End Color:</dt> <dd><wj-input-color value="chartProps.endColor"></wj-input-color></dd> <dt>End Offset:</dt> <dd> <wj-input-number control="inputEndOffset" value="chartProps.endOffset" min="0" max="1" step=".1"> </wj-input-number> </dd> <dt>End Opacity:</dt> <dd> <wj-input-number control="inputEndOpacity" value="chartProps.endOpacity" min="0" max="1" step=".1"> </wj-input-number> </dl>
// add data array to scope $scope.data = data; // add chart properties to scope $scope.chartProps = { gradientFill: '', gradientType: 'l', gradientDirection: 'horizontal', startColor: '#ff0000', startOffset: 0, startOpacity: 1, endColor: '#0000ff', endOffset: 1, endOpacity: 1 }; $scope.$watch('gradientChart', function () { var gradientChart = $scope.gradientChart; if (gradientChart != null) { applyGradientColor(); } }); $scope.$watch('chartProps.gradientType', function () { if ($scope.chartProps.gradientType != null) { applyGradientColor(); } }); $scope.$watch('chartProps.gradientDirection', function () { if ($scope.chartProps.gradientDirection != null) { applyGradientColor(); } }); $scope.$watch('chartProps.startColor', function () { if ($scope.chartProps.startColor != null) { applyGradientColor(); } }); $scope.$watch('chartProps.startOffset', function () { var inputStartOffset = $scope.inputStartOffset, val = $scope.chartProps.startOffset; if (inputStartOffset != null) { if (val < inputStartOffset.min || val > inputStartOffset.max || val >= $scope.chartProps.endOffset) { return; } applyGradientColor(); } }); $scope.$watch('chartProps.startOpacity', function () { var inputStartOpacity = $scope.inputStartOpacity, val = $scope.chartProps.startOpacity; if (inputStartOpacity != null) { if (val < inputStartOpacity.min || val > inputStartOpacity.max) { return; } applyGradientColor(); } }); $scope.$watch('chartProps.endColor', function () { if ($scope.chartProps.endColor != null) { applyGradientColor(); } }); $scope.$watch('chartProps.endOffset', function () { var inputEndOffset = $scope.inputEndOffset, val = $scope.chartProps.endOffset; if (inputEndOffset != null) { if (val < inputEndOffset.min || val > inputEndOffset.max || val <= $scope.chartProps.startOffset) { return; } applyGradientColor(); } }); $scope.$watch('chartProps.endOpacity', function () { var inputEndOpacity = $scope.inputEndOpacity, val = $scope.chartProps.endOpacity; if (inputEndOpacity != null) { if (val < inputEndOpacity.min || val > inputEndOpacity.max) { return; } applyGradientColor(); } }); function applyGradientColor() { if ($scope.gradientChart == null) { return; } var chart = $scope.gradientChart, color = '', props = $scope.chartProps, type = props.gradientType, direction = props.gradientDirection; color = type; if (type === 'l') { if (direction === 'horizontal') { color += '(0, 0, 1, 0)'; } else { color += '(0, 0, 0, 1)'; } } else { color += '(0.5, 0.5, 0.5)' } color += props.startColor; if (props.startOffset !== 0 && props.startOffset !== 1) { color += ':' + props.startOffset; } if (props.startOpacity !== 1) { color += ':' + props.startOpacity; } color += '-' + props.endColor; if (props.endOffset !== 0 && props.endOffset !== 1) { color += ':' + props.endOffset; } if (props.endOpacity !== 1) { color += ':' + props.endOpacity; } $scope.chartProps.gradientFill = color; chart.series[0].style = { fill: color }; }

#### Result (live):

  Column Bar Area SplineArea
Generated fill string:
  {{ chartProps.gradientFill }}
  Linear Radial
  Horizontal Vertical
Start Color:
Start Offset:
Start Opacity:
End Color:
End Offset:
End Opacity:

## Dynamic Charts

The FlexChart uses an ICollectionView internally, so any changes you make to the data source are automatically reflected in the chart.

In this sample, we use a timer to add items to the data source, discarding old items to keep the total count at 200. The result is a dynamic chart that scrolls as the new data arrives.

<wj-flex-chart items-source="trafficData" chart-type="Area" stacking="Stacked" binding-x="time"> <wj-flex-chart-axis wj-property="axisX" format="mm:ss"></wj-flex-chart-axis> <wj-flex-chart-series name="Trucks" binding="trucks"></wj-flex-chart-series> <wj-flex-chart-series name="Ships" binding="ships"></wj-flex-chart-series> <wj-flex-chart-series name="Planes" binding="planes"></wj-flex-chart-series> </wj-flex-chart> <div class="btn-group"> <button type="button" class="btn btn-default" ng-click="setInterval(200)">Slow</button> <button type="button" class="btn btn-default" ng-click="setInterval(100)">Medium</button> <button type="button" class="btn btn-default" ng-click="setInterval(50)">Fast</button> <button type="button" class="btn btn-default" ng-click="setInterval(0)">Stop</button> </div>
// dynamic data var toAddData; $scope.trafficData = new wijmo.collections.ObservableArray(); $scope.setInterval = function (interval) { if (toAddData) { clearTimeout(toAddData); toAddData = null; } $scope.interval = interval; if (interval) { toAddData = setTimeout(addTrafficItem); } }; $scope.setInterval(500); function addTrafficItem() { // add random data, limit array length ... // keep adding ... }

#### Result (live):

Update Speed