Jump to content
Software FX Community

Set gague properties in program code


Recommended Posts

Typically a user would want to specify ranges for gague colors rather than having these values fixed at design time, so we need to do it in the program.  e.g theseMax and Min values that can be set in the designer:

<ChartFXGauge:Section Bar-Color="255, 0, 0" Bar-Visible="False" Max="0.4" Min="-Infinity"></ChartFXGauge:Section>


ChartFXGauge:Section Bar-Color="255, 255, 0" Bar-Visible="False" Max="0.7" Min="0.4"></ChartFXGauge:Section>


ChartFXGauge:Section Bar-Color="124, 252, 0" Bar-Visible="False" Max="Infinity" Min="0.7"></ChartFXGauge:Section>

 How can we set these properties in the program?

Link to comment
Share on other sites


There are several question I would need you know to properly address your inquire. For example:

1) I am not sure if you have a constant number of sections. However you may divide the Max value for the mainindicator between the amount of sections to create as many sections as you need doing:

//settings for the sections

Section section1 = new Section ();

2) I guess you do not have in mind the colors you want to offer for each section, so you may follow this article to pick the color:


Then use the following to set the picked color for your section:

radialGauge1.MainScale.Sections[0].Color= NewColor;

3) Each section uses a Max and Min that can be set differently. If you want to allow the user also to set the Max and Min of each section, this will take a little more time. Once you get the Max and Min for a section you may use the following:

radialGauge1.MainScale.Sections[0].Min = Convert.ToDouble(NewMin.text);

radialGauge1.MainScale.Sections[0].Max = Convert.ToDouble(NewMax.text);

Your code at the end should look like this:

//settings for the sections

Section section1 = new Section ();

Section section2 = new Section ();

Section section3 = new Section ();

Section section4 = new Section ();

section1.Bar.Color = Color .Red;

section1.Max = 25;

section1.Min = 0;

section2.Bar.Color = Color .Orange;

section2.Max = 50;

section2.Min = 25;

section3.Bar.Color = Color .Yellow;

section3.Max = 75;

section3.Min = 50;

section4.Bar.Color = Color .Green;

section4.Max = 100;

section4.Min = 75;

radialGauge1.Scales[0].Sections.AddRange( new Section [] { section1, section2, section3, section4});

Link to comment
Share on other sites

1. In your example how does this code:

radialGauge1.MainScale.Sections[0].Min = Convert.ToDouble(NewMin.text);

radialGauge1.MainScale.Sections[0].Max = Convert.ToDouble(NewMax.text);

fit with the "at the end" code? Precedes it, goes after it, or?

For example it is not clear to me the relationship between

radialGauge1.MainScale and radialGauge1.Scales

2. How does the "at the end" code get linked to a specific grid instance like Grid1?

3. Suppose I already defined in the html, using the designer, a DataField with associated gague and sections.

Is it possible in the program code to change the min/max  values such as:

section1.Max = 25;

section1.Min = 0;

If so, how do I set up the proper reference to these properties in the grid created with the designer?

Link to comment
Share on other sites

Hello,Please keep in mind that Chart FX Gauges and Grid FX are two of our products, in the case of GridFX it can contain Chart FX Gauges to display data by simply format one of its cells as a Gauge. Therefore when you need to modify a Gauge you really should use Chart FX Gauge API and not GridFX API.

To make it more clear ...

1) Due to the fact that radialGauge1.Scales[0].Sections is the same as radialGauge1.MainScale.Sections[0], really this code:radialGauge1.MainScale.Sections[0].Min = Convert.ToDouble(NewMin.text);radialGauge1.MainScale.Sections[0].Max = Convert.ToDouble(NewMax.text);is the same as this:section1.Max = 25; section1.Min = 0; Therefore it comes after each color section:section1.Bar.Color = Color .Red;

2) By default you have always one scale, therefore if you do:radialGauge1.Scales[0].Sections.AddRange( new Section [] { section1, section2, section3, section4});

The following code will allow you to tide a Gauge to a Grid.

GridFX.WebForms.NumberField numField = (GridFX.WebForms.NumberField)Grid1.DataFields["rating"];// Let's show a Horizontal GaugeChartFX.WebForms.Gauge.HorizontalGauge Gauge1 = (ChartFX.WebForms.Gauge.HorizontalGauge)numField.Format.Gauge;// Let's create a LineraScale objectChartFX.WebForms.Gauge.LinearScale linearScale1 = (ChartFX.WebForms.Gauge.LinearScale)Gauge1.Scales[0];linearScale1.Max = 5d;linearScale1.Min = 1d;// Let's format the gauge with all previously customized attributes (Section/Indicator/needle/RadialScale)numField.Format.Gauge = Gauge1;

For more information you may open the RealState Sample provided with GridFX which contains more code sample.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...