Author Archives: Aaron Jacobson

Displaying Charts in ASP.NET MVC

Introduction

ASP.NET MVC allows very easy integration with Chart controls. ASP.NET contains a very powerful Chart control that provides a large set of chart options including bar, spine, columns, pie, pyramid, area and many more. It contains many elements that are accessible through the Chart control API. The major components of chart control are shown in the diagram below:Charts in ASP.NET MVC

Using Chart Control in ASP.NET MVC

Let’s create a sample application to show the use of chart control in Asp.Net MVC. We will create a project that shows the comparison of result in a class. To represent result of a particular student, we will use two fields- studentID and studentGrade.  We can easily modify the results and display the changes dynamically using Chart control.

As a first step, add a reference to the System.Web.UI.DataVisualization assembly. Restore the backup of database or execute script in database folder.

Now, chart control can be added to the View Page as shown below:

The above piece of code calls AddChart action with parameter Chart Type on Chart controller. Chart type parameters represents the type of chart. SeriesChartType represents an enumerator contained in the System.Web.UI.Charting namespace.

The code for action method AddChart in controller is shown below:

Chart class has many properties used to represent height, background color, border and many more. The main characteristics for any chart includes tile, ChartArea, legend and series.

Code to Create Chart Title:

The code below is used to create the title of chart. Text property is used to represent a title as shown below. In order to create multiple titles, add whatever is needed multiple times.

Code to Create Chart Legend:

The code below is used to modify the legend. It is similar as that of creating a title.

Code to Create Chart Series:

A datapoint is used to determine x and y elements of a chart control. Here we are using stdresults collection to get these values. Every value pair is added to the series chartPoints collection. There can be multiple series in a chart area and it is important to note which chart series is contained in which chart area. Similar to title and legend, we can change the look of series with different properties.

  • Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level
    Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
  • AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level
    The Fastest Way For .NET Developers To Add AngularJS To Their Resume
  • ASP.NET with Entity Framework from Scratch
    [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level
    Latest approach of web application development
  • Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels
    From zero knowledge of ASP.NET to deploying a complete project to production.

Code to Create Chart Area:

A chart contains many chart areas and a chart area is composed of multiple titles, series. A series contains multiple legends. It is possible to represent many chart series in same chart area or many chart areas in same chart.

The below code allows us to change different attributes of chart area including label style, axis label interval, color, font etc.  3D style can also be enabled here.

Author Bio:

Aaron Jacobson is a web developer working at Technoligent – asp.net development services. You can contact her in order to hire senior developers to avail the highly Java programming and web service. He has several years of experience in the field of web development.

Top 10 Interview Questions and Answers Series:

How to work with encoding in .NET?

Experts working in reputed .Net development company talk about the way to use .net functionalities to perform encoding in .net. Read this story and learn more about encoding.

Today I want to talk about how to use .NET functionalities to perform Encoding in .NET. For that purpose is first necessary to make a general overview around encoding patterns. Encoding is subject that causes a lot of confusion and is very misunderstood by developers.Encoding In .NET

You can imagine encoding patterns as a list of all possible characters belonging to that pattern. For example: the ASCII pattern has only English language characters and some punctuation characters. Since the ASCII was not suitable for some regions (where a language different from English is used), other patterns were created like UTF8, UTF16, etc…

Inside of namespace System. Text we have a call encoding, which centralizes all of work you’ve been doing if using encoding manually.
You can list all encodings available within your computer using the following code:

The class Encoding has a static method called GetEncodings, which returns an array of EncodingInfo type. The same has some properties which could be used for recovery of some information. In the example above we’ve used properties like CodePage, Name and DisplayName.

You may also use other methods provided by .NET framework, which provides several functionalities depending on your case. For example a GetBytes() method retrieves a bytes sequence for the text that we are trying to encode (using an encoder specified). Other is IsAlwaysNormalized() method, which retrieves a value that shows weather actual codification is always normalized.

For each character that you use in your string, there is corresponding byte sequence in the encoding that you choose. You can verify a difference of bytes executing the following code:

When you execute this code you will receive different representation for the letter “ç” depending on the encoding that you are using.

There is very important that you work with a right encoding when you perform Read/Write operations. In the example below is shown how to write a text using UTF7 encoding. And then following how a Read operation of the same text should be performed using right and wrong encoding.

You could understand that if we use wrong encoding than we may face several problems at the time of reading the text.

If you have a possibility to choose which class of encoding to use, go for UTF8Encodign or UnicodeEncodign (Recommendation of Microsoft), otherwise if there is impossible to use that encodings you can choose an encoding that is better fits your needs.

One more subtopic that is important to mention is related to the Encoding fallbacks. In the subject of encoding a fallback is a functionality which enables you to deal with unrecognized sequences of bytes (unrecognized characters). Basically when you try to encode or decode text which is not in the encoding you’ve choose, you must implement a way that will decide how the failed conversion should be handled.

You may have several custom strategies to apply in that situation, but I want to mention one that is the most used one, which is Replacement Fallback Strategy, basically in that situation when you encoding or decoding some text and for some reason no correspondent character is found, your fallback will replace that character with predefined one (For example the ASCII encoding when no corresponding character is found it replaces that character with a “?” mark).

You can find 2 methods to deal with that fallbacks in .NET an EncoderReplacementFallback and a DecoderReplacementFallback. This two methods have a “?” as a predefined letter to be replaced with unrecognized characters, but if you override their behavior you can choose your own symbol to be a default one for unrecognized characters.
We hope that it was useful and will save you much time with text Reading and Writing operations using .NET framework.

Hope the experts of .net development company have made you understand about the encoding functionality use in .net. You can still ask for more info related to encoding functionalities in comments.

Author bio:
Aaron Jacobson is working as content developer in a reputed asp.net Development company. You can share your thoughts regarding this post with her and suggest some topics. She will pick the interesting one and share her thoughts on the same.