Steps for getting started with the FlexChart control in MVC applications:
The FlexChart control has three properties that allow you to customize the chart type:
The example below allows you to see what happens when you change these properties:
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 that to use the LineSymbols chart type:
Use the Legend 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."
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:
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='"+@Url.Content("~/Content/images/{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.
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 MVC Controls 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:
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, MajorTickMarks and MajorGrid.) You can style the appearance of the features that are turned on using CSS.
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 MVC 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 it is contained in an element with the "wj-axis-x" class, which is contained in the the top-level control element, which 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 be have the "wj-flexchart" and the "custom-flex-chart" classes. Without this, the rule would apply to all charts on the page.
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.
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, 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 two methods: