416.467.9100 | Dundas Data Visualization | Login
Welcome Guest
This is the support page for the legacy Dundas Dashboard application. For assistance with the current Dundas BI application please click here.
Dashboard v5.0

This site makes extensive use of JavaScript.

Please enable JavaScript in your web browser and reload the page before proceeding.

Dynamically setting the start and end values on gauge ranges

Hide navigation
Modified on Fri, 31 Aug 2012 05:11 PM Categorized as Gauge, Script Library
&dw; Script LibraryPrevious

This script will allow you to set the start and end values on gauge ranges using data loaded from your database.

Note: You will have to change the script to reflect your column and control names.

The dataset

Create a dataset in your project that will contain the values you want to use for the ranges. On the dashboard, create a data grid and drop the data set in it.

Move the data grid outside of the dashboard canvas so it is not visible.

The data grid containing the values to use for the ranges.

The data grid containing the values to use for the ranges.

KPI states

In your KPI, create a state group with the states you want to use. The values are not important since the actual values will be changing using script.

Measure states in the KPI.

Measure states in the KPI.

State ranges in the gauge

After using your KPI on a gauge, the states will appear in the ranges collection. Here you can modify the ranges to look the way you want.

State ranges in a gauge.

State ranges in a gauge.

The script

Place this script in the dashboard's On Load Interactions list.


// Index to our columns int badStartIndex = 0; int badEndIndex = 0; int goodStartIndex = 0; int goodEndIndex = 0; int okStartIndex = 0; int okEndIndex = 0;

// Loop through our columns and find the index of our various columns int index = 0; foreach (object column in DataGrid1.Columns) { string columnName = column.ToString();

if (columnName == "BadStart") { badStartIndex = index; } if (columnName == "BadEnd") { badEndIndex = index; } if (columnName == "GoodStart") { goodStartIndex = index; } if (columnName == "GoodEnd") { goodEndIndex = index; } if (columnName == "OKStart") { okStartIndex = index; } if (columnName == "OKEnd") { okEndIndex = index; }

index++; }

// Grab the first row datapoint in our grid since object dp = DataGrid1.DataDescriptors[0].DataResult.DataPoints[0];

// Get the value in our columns double badStartValue = double.Parse(dp.FieldValues[badStartIndex].ToString()); ; double badEndValue = double.Parse(dp.FieldValues[badEndIndex].ToString()); ; double goodStartValue = double.Parse(dp.FieldValues[goodStartIndex].ToString()); ; double goodEndValue = double.Parse(dp.FieldValues[goodEndIndex].ToString()); ; double okStartValue = double.Parse(dp.FieldValues[okStartIndex].ToString()); ; double okEndValue = double.Parse(dp.FieldValues[okEndIndex].ToString()); ;

// Go through all the ranges and set their value foreach (DashboardRadialRange range in DynamicGauge.Scales[0].Ranges) { if (range.StateName == "Bad") { range.StartValue = badStartValue; range.EndValue = badEndValue; } if (range.StateName == "OK") { range.StartValue = okStartValue; range.EndValue = okEndValue; } if (range.StateName == "Good") { range.StartValue = goodStartValue; range.EndValue = goodEndValue; } }

Sample output

Sample output showing a gauge using default ranges and dynamic ranges.

Sample output showing a gauge using default ranges and dynamic ranges.

Related topics

About Dundas | Contact Us Follow us on Twitter! | Privacy Statement | Report Site Issues

Copyright © 2009-2014 Dundas Data Visualization, Inc.