Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Dynamically instantiating webgauge

Last post 05-06-2008 14:26 by [Infragistics] David Negley. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-29-2008 12:32

    Dynamically instantiating webgauge

    What is the minimum amount of code necessary to instantiate a visible webgauge?

    The following results in a blank page:

             private void AddGauge() {
                UltraGauge _gauge = new UltraGauge();
                _gauge.ID = "Gaugexx";
                _gauge.Gauges.AddRadialGauge();
                Controls.Add(_gauge);
            }

    Thanks,

     

    • Post Points: 35
  • 05-06-2008 14:15 In reply to

    Re: Dynamically instantiating webgauge

    you need more than you'd expect, as by default a radial gauge has 0 scales in it, and nothing has a brush set.  there's a fair amount of complexity we settled on in order to provide the most flexible object model possible.  i suggest either loading an xml preset, or using a wrapper class like "MiniGauge" here.

    (this class also contains the minimum amount of code needed to generate the gauge.)

     

    internal class MiniGauge : UltraGauge

    {

    public MiniGauge(): base()

    {

    LinearGauge lin = new LinearGauge();

    lin.Margin = new Margin(0.0);

    this.Gauges.Add(lin);

    lin.Scales.Add(new LinearGaugeScale());lin.Scales[0].Axis = new NumericAxis();

    lin.Scales[0].StartExtent = 0.0;

    lin.Scales[0].EndExtent = 100.0;

    lin.Scales[0].InnerExtent = 0.0;

    lin.Scales[0].OuterExtent = 100.0;

    LinearGaugeBarMarker marker = new LinearGaugeBarMarker();

    lin.Scales[0].Markers.Add(marker);

    marker.StartExtent = 0.0;

    marker.InnerExtent = 0.0;

    marker.OuterExtent = 100.0;

    SimpleGradientBrushElement markerBrush = new SimpleGradientBrushElement();

    marker.BrushElement = markerBrush;

    markerBrush.StartColor =
    Color.Yellow;

    markerBrush.EndColor = Color.Orange;

    markerBrush.GradientStyle = Gradient.Horizontal;

    SolidFillBrushElement backBrush = new SolidFillBrushElement(Color.Black);

    this.BackColor = Color.Blue;

    }

    public virtual double Value

    {

    get

    {

    return (double)((LinearGauge)this.Gauges[0]).Scales[0].Markers[0].Value;

    }

    set

    {

    ((
    LinearGauge)this.Gauges[0]).Scales[0].Markers[0].Value = value;

    }

    }

    }

     

    • Post Points: 5
  • 05-06-2008 14:20 In reply to

    Re: Dynamically instantiating webgauge

    The gauge is a empty control that needs for you to add all the gauge layers, scales, needles along with their properties set to some value in order for it to render something.  I would take a look at our documentation that shows how you can create these controls through code here:

    http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/Gauge_Creating_a_Gauge_Using_Code.html

    There should be three articles for each of the three types of gauges.  When navigating to each specific article, it will say Windows Forms, but like our chart control, the gauge code base can be used in a windows forms and asp.net environment.

    Also, due to the configuration necessary to produce these gauges, we provide 101 presets so that you may have a template to work with when implementing this control.  With that in mind, you should be able to create a gauge at design time and save to the preset to an xml file, which you can load using the LoadPreset method off the gauge.

    • Post Points: 5
  • 05-06-2008 14:26 In reply to

    Re: Dynamically instantiating webgauge

     oops, this sample was for linear gauges.  here's one for radial gauges:

    namespace WebApplication7
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MiniGauge g = new MiniGauge();
                g.Value = 3.14;
                this.FindControl("Form1").Controls.Add(g);
            }
        }
    }
    internal class MiniGauge : UltraGauge
    {
        public MiniGauge()
            : base()
        {
            RadialGauge rad = new RadialGauge();
            this.Gauges.Add(rad);
            SolidFillBrushElement dialBrush = new SolidFillBrushElement(Color.SkyBlue);
            rad.Dial.BrushElement = dialBrush;
            rad.Scales.Add(new RadialGaugeScale());
            rad.Scales[0].Axis = new NumericAxis();
            RadialGaugeNeedle needle = new RadialGaugeNeedle();
            rad.Scales[0].Markers.Add(needle);
            SolidFillBrushElement needleBrush = new SolidFillBrushElement(Color.Black);
            needle.BrushElement = needleBrush;
            rad.Scales[0].Labels.BrushElement = needleBrush;
            rad.Scales[0].MajorTickmarks.BrushElement = needleBrush;
        }
        public virtual double Value
        {

            get
            {
                return (double)((RadialGauge)this.Gauges[0]).Scales[0].Markers[0].Value;

            }

            set
            {
                ((RadialGauge)this.Gauges[0]).Scales[0].Markers[0].Value = value;

            }

        }

    }
     

    • Post Points: 5
Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems