Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Saturday, December 08, 2007

Google Chart


Google released Chart API which lets your web page to generate the Chart dynamically. Several types of image can be generated: line, bar, and pie charts for example. For each image type you can specify attributes such as size, colors, and labels.

How it works
- Request the url with chart parameters in query string, Google will response the “png” image chart.
E.g. http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello-YWorld-X
- Use with <img> tag
E.g. <img src="http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello-Y|World-X" /></IMG<>


Usage Policy
The Use of the Google Chart API is free but it is subject to a query limit of 50,000 queries per user per day. If you go over this 24-hour limit, the Chart API may stop working for you temporarily. If you continue to exceed this limit, your access to the Chart API may be blocked.

URL format
Google Chart API URLs must be in the following format:
http://chart.apis.google.com/chart?
chs=200x125
&chd=s:helloWorld
&cht=lc
&chxt=x,y
&chxl=0:|Mar|Apr|May|June|July|1:||50+Kb


Where:
· http://chart.apis.google.com/chart? is the Chart API's location.
· & separates parameters.
· chs=200x125 is the chart's size in pixels.
· chd=s:helloWorld is the chart's data.
· cht=lc is the chart's type.
· chxt=x,y indicates both x-axis and y-axis labels are required.
· chxl=0:|Mar|Apr|May|June|July|1:||50+Kb are the x-axis and y-axis labels.

Sample chart

Reference:
http://code.google.com/apis/chart/
Other Resources:
.Net server controls for google chart - http://pietschsoft.com/Blog/Post.aspx?PostID=1429

Have a nice day!

Wednesday, December 05, 2007

What's New in .Net 3.5

I have been checking about recently released .net 3.5 in these few days and there are many really pretty exciting features out there and also practically useful, applicable, lesser lines of code required and more productive in day to day works. I would say that Microsoft really made another major mile stone with .net framework achievement.

here are a few features I learned from the blogs and communities.

  1. Implicitly Type Local variables
  2. Anonymous Types
  3. Automatic Properties, Object Initializers, and Collection Initializers
  4. Extension Methods
  5. Lambda Expressions ( => )
  6. Language Integrated Query (LINQ)
  7. LINQ to SQL

1.Implicitly Type Local variables

Local variables can be given an inferred "type" of var instead of an explicit type. The var keyword instructs the compiler to infer the type of the variable from the expression on the right side of the initialization statement.

Compiler works for you to convert to the right type during compilation and so, from IL perspective, it sees as the type converted by compiler.

// i is compiled as an int

var i = 5;

// s is compiled as a string

var s = "Hello";

// a is compiled as int[]

var a = new[] { 0, 1, 2 };

// expr is compiled as IEnumerable<Customer>

var expr =

from c in customers

where c.City == "London"

select c;

// anon is compiled as an anonymous type

var anon = new { Name = "Terry", Age = 34 };

// list is compiled as List<int>

var list = new List<int>();

2.Anonymous Types

Anonymous types are a convenient language feature of C# and VB that enable developers to concisely define inline CLR types within code, without having to explicitly define a formal class declaration of the type.

Anonymous types are particularly useful when querying and transforming/projecting/shaping data with LINQ.

var person = new { FirstName = "Kyaw", LastName="Oo", BirthPlace="Yangon" };

Response.Write(person.FirstName);

For more detail, read here.

3.Automatic Properties, Object Initializers, and Collection Initializers

Isn’t it cool if you can write the class like below without requiring the private member and the compiler will automatically create the private members and map these to properties?

No need to declare private member and compiler will do it for you. But later if you want to modify the property for adding extra validation codes, you still can do without breaking to the client codes.

Automatic Properties

public class Person {

// Auto-implemented properties

public string FirstName { get; set; }
public string LastName { get; private set; } //Read Only
public int Age { get; set; }
}

Object Initializers

New alternative way of initializing the object. Cool, huh?

Person person = new Person { FirstName="Scott", LastName="Guthrie", Age=32 };

Collection Initializers

For more detail, read here.

4.Extension Methods

In old days, you will write your validation codes like below.

string email = Request.QueryString["email"];
if
( EmailValidator.IsValid(email) ) {
}

Have you ever thought about that you could write something like in C#, VB.NET? Now, it’s possible in .Net 3.5 .

string email = Request.QueryString["email"];
if(email.IsValidEmailAddress()) {

}

For more detail, read here.

5.Lambda Expression ( “=>” )

The => token is called the lambda operator. It is used in lambda expressions to separate the input variables on the left side from the lambda body on the right side. Lambda expressions are inline expressions similar to anonymous methods but more flexible; they are used extensively in LINQ queries that are expressed in method syntax.

string[] words = { "cherry", "apple", "blueberry" };

int shortestWord = words.Min(w => w.Length);

The => operator is read as "goes to." In the previous example, the expression is read as “Min w goes to w dot Length”.

The => operator has the same precedence as the assignment operator (=) and is right-associative.

public class Person

{

public string FirstName { get; set; }

public string LastName { get; set; }

public int Age { get; set; }

}

6.Language Integrated Query (LINQ)

This is the most productive and very useful feature in .Net 3.5 and it gives the developer to save the tremendous development time on data access layer codes.

Language Integrated Query (LINQ, pronounced "link") is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages using a syntax reminiscent of SQL.

http://en.wikipedia.org/wiki/Language_Integrated_Query

7.LINQ to SQL

This is how LINQ supported for SQL database. The following link will give you the comprehensive detail of LINQ – SQL insight.

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

For further reading:

http://weblogs.asp.net/scottgu/archive/2007/11/19/visual-studio-2008-and-net-3-5-released.aspx

http://resharper.blogspot.com/2007/10/c-30-automatic-properties-incomplete.html

Have a nice day!


kick it on DotNetKicks.com