Programming Interface (asp.net API)
The navigator is designed to function with any charts by changing single setting. (Chart.Navigator.Enabled = true) While all current chart types may not be supported, the goal is to support them all soon. There are two API layers in this navigator. One controls the UI and behavior and the other interacts with the chart in real-time.
A temporary directory setting is also required like with image charts where temporary data can be stored for the client to download. |
Enabling the Navigator
The following code snippen is an example of the required code to enable the Navigator.
chart.Navigator.Enabled = true
chart.TempDirectory = "temp"
chart.LegendBox.Position = LegendBoxPosition.ChartArea
Using the chart area legendbox position enabled richer functionality. |
UI / Behavior API
The chart.Navigator class contains almost all the settings to configure the different navigator options. They provide a way to turn interactivity features on and off, as well as showing and removing parts of the chart. These settings are broken into sections below.
Navigation Bar | |||||||||||||||||||||||||||||||||||
Disabling The Navigation Bar Disabling History Disabling Range Selectors Styling the bar Chart.Navigator.NavigationBar inherits from a Box class which offers all the styling properties such as background, padding, and corners. |
|||||||||||||||||||||||||||||||||||
Quick Zoom Buttons (Default Setting) Disabling Quick Zoom Buttons The Quick Zoom intervals are controled by a single string which can disable the buttons, make them determined automatically, specify what intervals to use, and optionally the label text of the buttons. The buttons support localization so users in different cultures will see the appropriate day/month abbreviations. The string takes a comma delimited list of intervals and supports custom label specification with an equal sign. Setting it to "Auto" will let the chart determine what the best buttons are. Syntax "[Multiplier][TimeInterval]=[Label],..." Intervals that are larger than the axis range or smaller than the zoomLimit will be omitted. |
| ||||||||||||||||||||||||||||||||||
Chart Area Legend | |||||||||||||||||||||||||||||||||||
Enabling ChartArea Legend Controling the range display Controling the display of a single element's value Arranging the range display mode
|
When the legend is not in the chart area it is not dynamic and it shows the values for the entire dataset. When the legend is placed inside the chart area however, it behaved dynamically by updating its value in real-time. The display of each series in the chart area as shown above can be specified through the respective LegendBox.Template. When the mouse is on the chart area, it displays the values of each element. This value can be specified with DefaultElement.SmartLabel.Text and all the element tokens can be used. By setting Series.LegendEntry.Value = "" for any series, the chart will not perform any calculations on the displaying info about the visible or highlighted range.
| ||||||||||||||||||||||||||||||||||
Chart Area | |||||||||||||||||||||||||||||||||||
Not showing the chart area Specifying UI Features Omiting any options will disable them. Specify drag area vs. selection area |
|||||||||||||||||||||||||||||||||||
Chart Area Axis | |||||||||||||||||||||||||||||||||||
Make cells smaller then axis ticks available
|
|||||||||||||||||||||||||||||||||||
Preview Area | |||||||||||||||||||||||||||||||||||
Specifying Preview Area Height Disabling/Hiding Preview Area Disable chart data drawing Specifying UI Features Omiting any options will disable them. |
The preview area provides a visual representation of the time range and data the scrollbar represents. They work together so disabling the scrollbar disables the preview as well. The preview area supports cell and arbitrary selection, dragging handles that mirror the scrollbar handles and scrollwheel zooming..
| ||||||||||||||||||||||||||||||||||
ScrollBar | |||||||||||||||||||||||||||||||||||
Disabling the Scrollbar
|
|||||||||||||||||||||||||||||||||||
General Options | |||||||||||||||||||||||||||||||||||
Chart Sizing A chart size can be specified in the traditional way. However, with the navigator, if the width or height is not specified, the chart will size to 100% of the available width or height. Disable Browser Status Help Messages
Silverlight plugin installation handling |
Specify Animation Duration (in milliseconds) Disable Mouse Tracking Limiting the zooming depth Set a starting zoom position Culcutre Settings Chart.DefaultCultureName = "en-US" |
Client Side Programming Interface (Real-Time JavaScript API)
Several properties and methods allow the chart to be manipulated through JavaScript and allows the chart to call functions and update objects on a page. For example the standard navigation bar on top of Navigator charts can be created from HTML elements and communicate with the chart through Javascript directly.
Control The Chart
In order to use the JavaScript interface of the silverlight chart, a unique ID must be specified for the control like with the following asp.net code
Chart.Navigator.ControlID = "slPlugin"
Now the chart object can be accessed from JavaScript on the page. Consider the following code snippet:
<script type="text/javascript">
var chartID = "slPlugin";
function goback() {
var control = document.getElementById(chartID);
control.Content.Chart.PageLeft();
}
</script>
This code defines a function that accesses the chart object and calls the chart's PageLeft() method.
Getting information from the Chart
The Javascript chart interface provides the ability to get information about the position status of the chart. The following JavaScript method gets the time range of the visible chart area and updates the visible range to show only the last 10 days from the current right position.
<script type="text/javascript">
var chartID = "slPlugin";
function leftten() {
var control = document.getElementById(chartID);
var range = control.Content.Chart.GetVisibleRange();
var leftDate = range.ValueHigh;
var tmpDate = range.ValueHigh;
leftDate.setDate(leftDate.getDate() - 10);
control.Content.Chart.NavigateToVisibleRange(leftDate, tmpDate);
}
</script>
Chart Controlling the Page
The chart can call a Javascript functon when the viewport is updated by the user and it can update an HTML element with a help message text.
The following example will let the chart update the text of a div element with a help message while using the navigator. The first part of this task requires registering a method or property with the chart. Consider the following JavaScript code.
<script type="text/javascript">
var chartID = "slPlugin";
// This function registers the location update handler when the silverlight chart loads.
function initEvents() {
var control = document.getElementById("slPlugin");
if (control) {
control.Content.Chart.SetHelpMessageHost("helpDiv.innerHTML");
clearInterval(initID);
}
}
// Try to register the location update handler with the chart until it is succeeds.
var initID = setInterval("initEvents()", 1000);
</script>
The initEvents() method tells the chart to update the innerHTML property of the div tag named helpDiv with a help message. The if, else statement ensures that the silverlight control is loaded before this property is assigned. If it is not loaded, it waits 1000 milliseconds before it tries again.
Slideshow Presentation with Navigator
Including a Navigator chart in a slideshow presentation is easy to do. Refer to sample [Feature Set > Navigator > NavigatorSlideshow]
It contains information about the slideshow in javascript arrays including a text message, delay in milliseconds, and left and right positions to move the chart for each slide.
var myTextArr = [...];
var delayArr = [...];
var leftDTArr = [...];
var rightDTArr = [...];
A displaySlide function will update the page with the specified slide.
function displaySlide(frame) {
var control = document.getElementById(chartID);
control.Content.Chart.NavigateToVisibleRange(leftDTArr[frame], rightDTArr[frame], delayArr[frame])
var tText = myTextArr[frame];
setTimeout('displayText("' + tText + '");', delayArr[frame]);
}
The startSlideshow() function initiates the slide show and playSlide() function handles itarating the slides with a delay between them. playSlide() ensures only the available slides are shown and initiates the next slide by calling itself on a delay.
function startSlideshow() {
playSlide(0)
}
function playSlide(frame) {
displaySlide(frame);
var nextFrame = frame + 1;
if (nextFrame < myTextArr.length) {
setTimeout('playSlide(' + nextFrame + ')', delayArr[frame] + slidesPause);
}
}
Possible Uses
The interface is designed to allow users to use the chart to control content of the page or let the content of your page control the chart itself. The chart is able to animate between views of data such as zooming in or out which gives the user a better idea of how a subset of the the data relates to a bigger picture. A page that lets the user navigate articles related to specific dates for example can update the chart view to encompass data that is related to those articles.
A page that emulates a slideshow type movie can be connected to a chart so that when each slide is shown the chart animates to the appropriate data. Methods that control the navigation also provide the option to specify the duration any animation between the different ranges.
Javascript Interface Reference
Below is a list of available methods provided by this interface.
Method/Property | Description |
Control The Chart | |
PageLeft() | Pages the scrollbar left. |
PageRight() | Pages the scrollbar right. |
NavigatorForward() | Navigates the zoomer forward to the next location. Same as clicking the forward button on the navigation bar. |
NavigateBack() | Navigates the zoomer back to the previous location. Same as clicking the back button on the navigation bar. |
NavigateToCenter (object centerVal, int milliseconds) |
Animates the zoomer to center at the specified x axis value maintaining the scrollbar width in the specified amount of time.
|
NavigateToCenter (object centerVal) |
Animates the zoomer to center at the specified x axis value maintaining the scrollbar width.
|
NavigateToVisibleRange (object leftVal, object rightVal, int milliseconds) |
Animates the view to the specified x axis value range in the specified amount of time.
|
NavigateToVisibleRange (object leftVal, object rightVal) |
Animates the view to the specified x axis value range.
|
NavigateToVisibleRangePerc (double left, double right, int milliseconds) |
Animates the view to the specified percentage range in the specified amount of time. The percentage range is a numeric value from 0 to 1 representing the maximum left and right positions. A range of 0 to 1 means the chart is fully zoomed out.
|
NavigateToVisibleRangePerc (double left, double right) |
Navigates the view to the specified percentage range. The percentage range is a numeric value from 0 to 1 representing the maximum left and right positions. A range of 0 to 1 means the chart is fully zoomed out.
|
Get info from chart. | |
ScaleRange GetVisibleRangePerc() | Gets the visible x axis percentage range. The percentage range is a numeric value from 0 to 1 representing the viewport left and right positions. A resulting range of 0 to 1 means the chart is fully zoomed out. |
ScaleRange GetVisibleRange() | Gets the visible x axis range values. |
Have the chart control the page. | |
SetLocationUpdateHandler(string) | Sets the name of a JavaScript method with two parameters (lowValue, highValue) on the current page that will be called when the chart viewport is updated and the new range will be passed to it. |
SetHelpMessageHost(string) | Sets the property of an HTML or Javascript object on the page which will be updated by the chart with a help message when the user is interacting with the chart. |
Notes:
JavaScript DateHandling When creating a DateTime value in javascript to pass to the chart, a date specified with new Date(2010, 0, 0, 18, 0, 0) in Javascript is equivalent to the .net new DateTime(2010,1,1). |
Range vs RangePerc The range represents the actual values of the x axis and can be given in DateTime or numeric data types. Category scales also use a numeric scale range numbering each element name from 0-n. |
Performance Considerations
This chart is designed to animate large sets of data smoothly utilizing silverlight which is a subset of WPF. While WPF has very powerful graphics capabilities, silverlight does not have all the same capabilities of WPF. There are a few things that can help improve the performance of your charts if they become to slow down.
Bar Charts
A bar series includes some extra graphical elements such as a borders and the bar face itself. A chart with thousands of such bars can be made much more efficient utilizing the finance bar series types. This will make the bars thin but when so many bars are available they will usually be very close together anyway. However, these bar widths can be controled with Series.Line.Width . Using the following code a series can be converted to utilize this performance enhancement.
C# Example | Copy Code |
---|---|
mySeries.Type = SeriesTypeFinancial.Bar; // In order to improve the performance of this chart, the volume series will utilize the finance bars instead of full columns. foreach (Element el in mySeries.Elements) { // This applies the y value to high and 0 to low so that the finance bars appear as a column series would. el.High = el.YValue; el.Low = 0; } |
Visual Basic Example | Copy Code |
---|---|
mySeries.Type = SeriesTypeFinancial.Bar ' In order to improve the performance of this chart, the volume series will utilize the finance bars instead of full columns. For Each el As Element In mySeries.Elements ' This applies the y value to high and 0 to low so that the finance bars appear as a column series would. el.High = el.YValue el.Low = 0 Next |
Line and AreaLine Marker Behavior
Lines with many points have element markers for each. When these elements exceed a count of 250 the element markers will automatically be removed. However, in charts with fewer points, removing the element markers can also improve performance.
Chart Size
The chart size has a great influence on animation performance. If the charts starts getting slow, making it smaller is likely to speed it up a great deal.
Mouse Tracking
Disabling mouse tracking can improve performance of client side charts when the user hovers their mouse over the chart areas.
Element Hotspots
Using element hotspots to make them clickable or with tooltips can add also add a performance penalty when the user hovers their mouse over the chart areas.
Axis AlternateGridBackground & GridLines
Everything that needs to move on the chart area requires processing time. Disabling the alternateGridBackground color can help as a start. In addition, disabling gridlines can help also.
Axis Scale
The chart is capable of scrolling easily, however, when the y axis range updates dynamically the chart area must not only scroll but also scale everything on it. Setting a static axis range (YAxis.ScaleRange = ...) can lock in the axis range making the chart very fast to scroll and zoom.
Caching
The server side processing can be cached so that each request of a page with charts on them doesnt require generating them each time. To use this feature, you must set a static filename for the chart such as: Chart.FileName = "ChartA1"; Then enable fragment caching for the hosting aspx page.
For more information see: - How To Perform Fragment Caching in ASP.NET by Using Visual C# .NET |
Tutorials
Overview
User Interface