Main Menu
Knowledge Base
Product Registration
Log an Incident
Request a Feature
Search Incidents/Bug Reports


Search KB

Please note: In an effort to better serve you, we are in the process of restructuring DevCenter. In the process, we have moved many items that you may be used to finding in DevCenter over to the Main Site. If you are having trouble locating something, please try looking at the following places:

Knowledge Base Article: KB09974

HOWTO:Drill down in WinChart [Part 4]


The information in this article applies to:
UltraWinChart (v6.1.20061)
  Article Created: 
6/22/2006

Last Updated:
6/26/2006

Article Type
How To
  
Page Options
Average Rating:
2 out of 10

Rate this page
Print this page
E-mail this page
Add to Favorites

Summary

..Continued..

Step-By-Step Example

C#

        ///
        /// This method accepts an argument, that depending on the
        /// current drill level, represents one of several possible
        /// entity fields (Customer ID, Order Number, etc...) and
        /// then allows us to build a query to fetch data for one
        /// of several drill levels
        ///

        ///
        private void BuildChart(string FieldValue)
        {
            SqlCommand theCommand = new SqlCommand();
            theCommand.Connection = this.sqlConnection1;
            theCommand.CommandType = CommandType.Text;

            string s = string.Empty;

            switch (_currDrill)
            {
                case 1: // FieldValue should be null at this level
                    
                    //Build the command
                    s += " select TOP 10 a.customerID as 'Customer', count(b.OrderID) as 'Order Count' ";
                    s += " FROM ";
                    s += " Customers a, Orders b ";
                    s += " WHERE a.CustomerID = b.CustomerID ";
                    s += " GROUP BY a.CustomerID ";
                    s += " ORDER BY 2 DESC ";                    
                    
                    theCommand.CommandText = s;

                    // Set Chart properties for this drill level:
                    this.ultraChart1.ChartType = ChartType.BarChart3D;
                    this.ultraChart1.Legend.Visible = true;
                    
                    // Set DataSource:
                    this.ultraChart1.Data.DataSource = this.GetChartData(theCommand);

                    // Set link labels for this level:
                    this.lnk1.Text = "Root";

                    this.lnk1.Enabled = false;
                    this.lnk1.Visible = true;
                    
                    this.lnk2.Enabled = false;
                    this.lnk2.Visible = false;
                    
                    this.lnk3.Enabled = false;
                    this.lnk3.Visible = false;

                    //set the ui labels for this level:
                    this.lbl1.Enabled = true;
                    this.lbl2.Enabled = false;
                    this.lbl3.Enabled = false;

                    break;

                case 2: //Level 2: We can get the actual Orders PER customer
                                        
                    //Build the command
                    s += "select TOP 10 CONVERT(VARCHAR(10), a.OrderID) as 'Order ID',count(b.OrderID) as 'Line Items' ";
                    s += " FROM Orders a, [Order Details] b ";
                    s += " WHERE a.OrderID = b.OrderID AND ";
                    s += " a.CustomerID = @CustomerID ";
                    s += " group by a.OrderID order by 2 DESC ";
                    
                    theCommand.CommandText = s;

                    theCommand.Parameters.Add("@CustomerID", FieldValue);

                    // Set Chart properties for this drill level:
                    this.ultraChart1.ChartType = ChartType.PieChart3D;
                    this.ultraChart1.PieChart3D.Labels.FormatString = "<DATA_VALUE:0> Line Items";
                    this.ultraChart1.Legend.Visible = true;    

                    // Set DataSource:
                    this.ultraChart1.Data.DataSource = this.GetChartData(theCommand);

                    // Set link labels for this level:
                    this.lnk1.Enabled = true;
                    this.lnk1.Visible = true;
                    
                    this.lnk2.Text = FieldValue;
                    this.lnk2.Enabled = false;
                    this.lnk2.Visible = true;
                    
                    this.lnk3.Enabled = false;
                    this.lnk3.Visible = false;

                    //set the ui labels for this level:
                    this.lbl1.Enabled = false;
                    this.lbl2.Enabled = true;
                    this.lbl3.Enabled = false;

                    break;

                case 3:
                    //Build the command
                    s += " select a.ProductName as 'Product', b.Quantity as 'Quantity' ";
                    s += " FROM Products a, [Order Details] b WHERE a.ProductID = b.ProductID ";
                    s += " AND b.OrderID = @OrderID ORDER BY b.Quantity ASC";
                    
                    theCommand.CommandText = s;

                    theCommand.Parameters.Add("@OrderID", FieldValue);

                    // Set Chart properties for this drill level:
                    this.ultraChart1.ChartType = ChartType.CylinderColumnChart3D;
                    this.ultraChart1.Legend.Visible = true;

                    // Set DataSource:
                    this.ultraChart1.Data.DataSource = this.GetChartData(theCommand);

                    // Set link labels for this level:
                    this.lnk1.Enabled = true;
                    this.lnk1.Visible = true;
                    
                    this.lnk2.Enabled = true;
                    this.lnk2.Visible = true;
                    
                    this.lnk3.Text = FieldValue;
                    this.lnk3.Enabled = false;
                    this.lnk3.Visible = true;

                    //set the ui labels for this level:
                    this.lbl1.Enabled = false;
                    this.lbl2.Enabled = false;
                    this.lbl3.Enabled = true;

                    break;

                default:
                    throw new ApplicationException("Unhandled Drill Level");
            }
        }

The Build Chart method accepts a string that represents the value of an entity which will be used to build a SQL query so that we can fetch the appropriate chart data. The value of the parameter represents a field from each of the different entities which vary from drill level to drill level. For example, if we are on “Level 1”, we do not even need to pass in a value, we just pass in Null or Nothing because at “Level 1”, we simply load all customers. If we are on “Level 2”, the method parameter reflects one particular CustomerID, which is an attribute of the Customer entity. On “Level 3”, the same parameter represents the Order ID of the Order entity. The main point is that for each level, we must clearly define what entity attribute is represented by the parameter so that all we have to do in code is use the drill level along with the parameter value to build a query that fetches data from the appropriate database tables.

Notice the simple pattern being used for the case of each drill level. We build a query and SqlCommand object, we then set the Chart properties, we then get the Data and bind it to the Chart and finally, we update each UI and navigation element so that it makes sense for that drill level. When we think about it, this makes sense; if we are on “Level 1”, the root Link Label should not be enabled. We should not be able to click on Link Label 1 to go to “Level 1” because at this point, we are already at that level. If we are on “Level 2”, Link Label 1 should be enabled so that we can navigate back and Link Label 2 should now have text that represents the customer that we clicked on from “Level 1”; also Link Label 2 should be disabled. Additionally, we must only see Link Labels up to the current drill level; we should not see Link Labels for drill levels that we have not navigated to yet.
..Continued..

Related Articles

HOWTO: Drill down in WinChart [Part 6] (KB09978)

HOWTO: Drill down in WinChart [Part 5] (KB09975)

HOWTO: Drill down in WinChart [Part 3] (KB09973)

HOWTO: Drill down in WinChart [Part 2] (KB09972)

HOWTO: Drill down in WinChart [Part 1] (KB09971)

Samples

winchart_drilldown.zip
 WinChart Drilldown Samples in C# and VB.NET



How would you rate the quality of this content?
Poor -----------------------------------------> Outstanding

Tell us why you rated the content this way. (optional)