Devexpress仪表的实时更新

时间:2015-08-15 21:52:12

标签: c# asp.net devexpress

我已经设法使用Devepxress按照他们的代码示例创建一个循环测量但我有一个问题。创建控件后,我不知道如何使用它们的函数来更新控件。

他们确实有一个如何使用updatepanel的例子,所以我认为我最好的选择是动态添加一个更新面板,但是我如何将它附加到每个创建的控件上,以便只有那个会改变它的一个控件值

https://documentation.devexpress.com/#AspNet/CustomDocument11286

表单加载代码:

dgh.CreateCircularGauge(25, pnlTorgue);
dgh.CreateCircularGauge(45, pnlRpm);
dgh.CreateCircularGauge(75, pnlSpeedkmh);
dgh.CreateThemomenter(85, pnlEngTemp);

**我想从这个问题中得到什么**

能否说dgh.CreatCircularGuage(oldValue,NewValue,UpdateBoolean,mypanel); 所以我可以使用aspxtimer tick事件来调用它?这可能吗

public  void CreateCircularGauge(int guageValue, Panel mypanel)
{
        // Creates a new instance of the ASPxGaugeControl class with default settings.
        ASPxGaugeControl gaugeControl = new ASPxGaugeControl();
        gaugeControl.EnableCallbackAnimation = true;

        // Creates a new instance of the CircularGauge class and adds it
        // to the gauge control's Gauges collection.
        CircularGauge circularGauge = (CircularGauge)gaugeControl.AddGauge(GaugeType.Circular);

        // Adds the default elements (a scale, background layer, needle and spindle cap).
        circularGauge.AddDefaultElements();

        // Changes the background layer's paint style.
        ArcScaleBackgroundLayer background = circularGauge.BackgroundLayers[0];
        background.ShapeType = BackgroundLayerShapeType.CircularFull_Style2;

        // Customizes the scale's settings.
        ArcScaleComponent scale = circularGauge.Scales[0];
        scale.MinValue = 0;
        scale.MaxValue = 100;
        scale.Value = guageValue;
        scale.MajorTickCount = 6;
        scale.MajorTickmark.FormatString = "{0:F0}";
        scale.MajorTickmark.ShapeType = TickmarkShapeType.Circular_Style1_2;
        scale.MajorTickmark.ShapeOffset = -9;
        scale.MajorTickmark.AllowTickOverlap = true;
        scale.MinorTickCount = 3;
        scale.MinorTickmark.ShapeType = TickmarkShapeType.Circular_Style2_1;
        scale.AppearanceTickmarkText.TextBrush = new SolidBrushObject(Color.Gray);

        // Changes the needle's paint style.
        ArcScaleNeedleComponent needle = circularGauge.Needles[0];
        needle.ShapeType = NeedleShapeType.CircularFull_Style3;

        // Adds the gauge control to the Page.
        gaugeControl.Width = 250;
        gaugeControl.Height = 250;
        gaugeControl.AutoLayout = true;

        mypanel.Controls.Add(gaugeControl);

 }

1 个答案:

答案 0 :(得分:0)

要单独更新每个仪表,最佳解决方案是使用ASPxGaugeControl.PerformCallback方法。您应该在Timer客户端事件中调用此方法,然后在服务器端处理ASPxGaugeControl.CustomCallback事件以根据需要更新gauge的值:

<script type="text/javascript">
        var isDirty;
        function gaugePerformCallback() {
            var gauge = window['gauge'];
            isDirty = gauge.InCallback();
            if (!isDirty)
                gauge.PerformCallback();
        }
        function gaugeEndCallback() { 
            if (isDirty)
                window.setTimeout(function() { gaugePerformCallback() }, 0);
        }
</script>

...
<dx:ASPxGaugeControl runat="server" Width="250px" Height="250px" BackColor="Transparent" ID="gaugeControl" ClientInstanceName="gauge"
    SaveStateOnCallbacks="false">
    <ClientSideEvents EndCallback="gaugeEndCallback" />
    ...
</dx:ASPxGaugeControl >
<dx:ASPxTimer ID="timer" runat="server" Interval="500">
    <ClientSideEvents Tick="function(s, e) {
                gaugePerformCallback();
         }"></ClientSideEvents>
</dx:ASPxTimer>

服务器端代码隐藏:

void gaugeControl_CustomCallback(object source, DevExpress.Web.CallbackEventArgsBase e) {
    gaugeControl.Value = /* value */;
}