BusyIndicator with RadCartesianChart

3 posts, 0 answers
  1. Alberto
    Alberto avatar
    26 posts
    Member since:
    Nov 2012

    Posted 30 Sep 2013 Link to this post

    Hello,

    I am trying to implement a BusyIndicator when loading data into a RadCartesianChart.

    I have this code:

    <telerik:RadBusyIndicator Name="busyInd" HorizontalAlignment="Left"  Grid.Row="1" Margin="10,10,0,0" VerticalAlignment="Top" Height="255" Width="372" IsIndeterminate="True">
     
            <telerik:RadCartesianChart x:Name="CartesianChartDemo" Grid.Column="5" Margin="10" Grid.Row="2" Grid.ColumnSpan="3">
     
                <telerik:RadCartesianChart.Behaviors>
                    <telerik:ChartPanAndZoomBehavior PanMode="Both" ZoomMode="Both"/>
                </telerik:RadCartesianChart.Behaviors>
     
            </telerik:RadCartesianChart>
     
    </telerik:RadBusyIndicator>

    I load data in the code behind file:

    CartesianChartDemo.VerticalAxis = new CategoricalAxis();
                CartesianChartDemo.HorizontalAxis = new LinearAxis();
     
                CartesianChartDemo.Grid = new CartesianChartGrid() { MajorLinesVisibility = GridLineVisibility.XY };
     
                string strQuery = "MyQuery";
     
    //Function to get datatable
                DataTable dtAlloys = DataRetriever.GetDataTable(strQuery);
                
                BarSeries barSer = new BarSeries();
                barSer.ShowLabels = true;
                barSer.CombineMode = ChartSeriesCombineMode.Cluster;
     
                BarSeries barSer2 = new BarSeries();
                barSer2.ShowLabels = true;
                barSer2.CombineMode = ChartSeriesCombineMode.Cluster;
     
                foreach (DataRow drAlloy in dtAlloys.Rows)
                {
                    barSer.DataPoints.Add(new CategoricalDataPoint() { Category = drAlloy["MATERIAL_CODE"], Label = string.Format("{0:N}", drAlloy["WT"]), Value = double.Parse(drAlloy["WT"].ToString()) });
                    barSer2.DataPoints.Add(new CategoricalDataPoint() { Category = drAlloy["MATERIAL_CODE"], Label = string.Format("{0:N}", drAlloy["TARG"]), Value = double.Parse(drAlloy["TARG"].ToString()) });
                }
     
                CartesianChartDemo.Series.Clear();
                CartesianChartDemo.Series.Add(barSer);
                CartesianChartDemo.Series.Add(barSer2);

    I was thinking to add:

    busyInd.IsBusy = true;
     
    //Code to load data
     
     
    busyInd.IsBusy = false;

    But I'm not sure if this is the way the BusyIndicator works.

    Does anyone has any pointers to accomplish that?

    Regards,

    Alberto


  2. Alberto
    Alberto avatar
    26 posts
    Member since:
    Nov 2012

    Posted 01 Oct 2013 Link to this post

    I think I have a possible solution:

    I took some code from the WPF Control Examples Demo:

    //Show the busy indicator
    busyInd.IsBusy = true;
     
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += this.OnBackgroundWorkerDoWork;
    backgroundWorker.RunWorkerCompleted += OnBackgroundWorkerRunWorkerCompleted;
    backgroundWorker.RunWorkerAsync();

    private void OnBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
            {
                //Get data table
                e.Result = GetData();
            }

    private void OnBackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                var backgroundWorker = sender as BackgroundWorker;
                backgroundWorker.DoWork -= this.OnBackgroundWorkerDoWork;
                backgroundWorker.RunWorkerCompleted -= OnBackgroundWorkerRunWorkerCompleted;
                
                // Hide busy indicator
                busyInd.IsBusy = false;
     
                ConfigureChart((DataTable)e.Result);
            }

    void ConfigureChart(DataTable dtAlloys)
            {
                try
                {
                    CartesianChartDemo.VerticalAxis = new CategoricalAxis();
                    CartesianChartDemo.HorizontalAxis = new LinearAxis();
     
                    BarSeries barSer = new BarSeries();
                    barSer.ShowLabels = true;
                    barSer.CombineMode = ChartSeriesCombineMode.Cluster;
     
                    BarSeries barSer2 = new BarSeries();
                    barSer2.ShowLabels = true;
                    barSer2.CombineMode = ChartSeriesCombineMode.Cluster;
                     
                    foreach (DataRow drAlloy in dtAlloys.Rows)
                    {
                        barSer.DataPoints.Add(new CategoricalDataPoint() { Category = drAlloy["MATERIAL_CODE"], Label = string.Format("{0:N}", drAlloy["WT"]), Value = double.Parse(drAlloy["WT"].ToString()) });
                        barSer2.DataPoints.Add(new CategoricalDataPoint() { Category = drAlloy["MATERIAL_CODE"], Label = string.Format("{0:N}", drAlloy["TARG"]), Value = double.Parse(drAlloy["TARG"].ToString()) });
                    }
     
                    CartesianChartDemo.Series.Clear();
                    CartesianChartDemo.Series.Add(barSer);
                    CartesianChartDemo.Series.Add(barSer2);
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error", ex.Message);
                }

    And that's it, it works as I needed.

    Regards,

    Alberto

  3. UI for WPF is Visual Studio 2017 Ready
  4. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 02 Oct 2013 Link to this post

    Hi Alberto,

    Indeed, that is the right way to use RadBusyIndicator.

    If you have any further questions, write to us again.

    Regards,
    Yana
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top