Scroll

Custom Function: Dynamic Rank

Users may want to be able to dynamically display an image representing the rank, or rating, using an image displaying a number of stars. This example assumes the Load Image Prefix setting in the Admin Console is in use and that each potential rank image follows the same naming format. This example also assumes an external language file for the error message. Be sure to add the language element to an external file, and reference that file in the Main Settings of your Admin Console. For a walkthrough of the usage of this function, take a look at the Dynamic Rank Custom Function Support Lab

Arguments (Min - Max): 1-1

Namespaces:

  • WebReports.Api.Reports

Usage

DynamicRank(rank)

  • rank is a numeric value greater than or equal to 0 and less than or equal to 5.

Code:

//Check for invalid input
string Rank = args[0].ToString();
double rank;
if(!double.TryParse(Rank, out rank) || 0 > rank || rank > 5)
{
return sessionInfo.PageInfo.LanguageDict.GetInfo("InvalidInput").Html.ToString(); } // Create file name to be appended to LoadImage prefix. string file = "rank_" + (Math.Round(rank * 2) / 2).ToString() + ".png"; // Create formula text. string formulaText = String.Format("=LoadImage(\"{0}\")", file); // Create embedded formula for LoadImage function CellFormula formula = CellFormula.CreateFormula(sessionInfo.PageInfo, formulaText, CellVariableCollectionFilter.DataField); // evaulate and return result return formula.Evaluate(null);

Hidden Article Information

Article Author
Emma
created 2019-04-10 16:55:46 UTC
updated 2019-05-16 20:33:35 UTC

Labels
no labels yet!
Have more questions? Submit a request