Wednesday, December 22, 2010

ASP.NET Error Bar Chart

The Error Bar chart type consists of lines with markers that are used to display statistical information about the data displayed in a graph. A series of the Error Bar chart type has three Y values. While these values can be manually assigned to each point, in most cases, the values are calculated from the data present in another series. The order of the Y values is important because each position in the array of values represents a value on the error bar.

Adding Error Bar series to another series on same chart
Lets say we have a chart named Chart1 and series named Series1. 
We can add the Error Bar series to Series1 using the following snippet...
     Series errorBarSeries = new Series("ErrorBar");  
            errorBarSeries.ChartType = SeriesChartType.ErrorBar;  
            errorBarSeries.MarkerBorderColor = Color.FromArgb(64, 64, 64);  
            errorBarSeries.MarkerSize = 6;  
            errorBarSeries.YValuesPerPoint = 3;  
            errorBarSeries.BorderColor = Color.FromArgb(180, 26, 59, 105);  
            errorBarSeries.Color = Color.FromArgb(252, 180, 65);  
            errorBarSeries.ShadowOffset = 1;  
            errorBarSeries.MarkerStyle = MarkerStyle.None;  
            errorBarSeries["PointWidth"] = "0.1";  
            double error = 100;  
            foreach (DataPoint point in Series1.Points)  
                double centerY = point.YValues[0];  
                double lowerErrorY = centerY - error;  
                double upperErrorY = centerY + error;  
                errorBarSeries.Points.AddXY(point.XValue, centerY, lowerErrorY, upperErrorY);  
Calculating Error Values from Another Series
This can be done using the following code snippet.

  // Populate series with data
    double[]    yValues = {32.4, 56.9, 89.7, 98.5, 59.3, 33.8, 78.8, 44.6, 76.4, 68.9};

    // Set error bar chart type
    chart1.Series["ErrorBar"].ChartType = SeriesChartType.ErrorBar;

    // Link error bar series with data series
    Chart1.Series["ErrorBar"]["ErrorBarSeries"] = "DataSeries";

    // Set error calculation type
    Chart1.Series["ErrorBar"]["ErrorBarType"] = "StandardError";

    // Set error bar upper & lower error style
    Chart1.Series["ErrorBar"]["ErrorBarStyle"] = "UpperError";

    // Set error bar center marker style
    Chart1.Series["ErrorBar"]["ErrorBarCenterMarkerStyle"] = "Circle";
Adapted from:
MSDN Error Bar Chart     
Social MSDN Error Bar Chart

Wednesday, December 01, 2010

Using osql to do backup/restore and escaping special characters in 'LIKE'

Using osql util
Some quick quips to share on Sql Server on using osql command line util to performe  backups/restore
osql -E -Sinstancename -q "BACKUP DATABASE [dbname] TO  DISK = N'backupfile.bak' WITH NOFORMAT, INIT,  NAME = N'dbName Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10"
osql -E -Sinstancename  -q "RESTORE DATABASE [dbname] FROM  DISK = N'backupfile.bak' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10"
Using 'LIKE'
Using 'LIKE' to determine if a value or a column of values IS ALL DIGITS
SELECT * FROM testtable WHERE columnxyz NOT LIKE '%[^0-9]%'

'^' means 'NOT', so the expression above evaluates to 'Select only rows from testtable where everything in the columnxyz is a digit from 0 to 9'
Use the ESCAPE clause and the escape character in order to use special characters in your expression.
E.g. to find the exact character string 10-15% in column c1 of the mytbl2 table, we use
SELECT c1 FROM mytbl2 WHERE c1 LIKE '%10-15!% off%' ESCAPE '!'
Further reading on the BOL LIKE reference