<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Column Charts &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/column-charts/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:16:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Column Charts &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Chart Widgets With Server Side Data In MVC Using Angular JS And Web API</title>
		<link>https://www.sibeeshpassion.com/chart-widgets-with-server-side-data-in-mvc-using-angular-js-and-web-api/</link>
					<comments>https://www.sibeeshpassion.com/chart-widgets-with-server-side-data-in-mvc-using-angular-js-and-web-api/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 17 Mar 2016 05:33:35 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[Angular JS]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Bar Chart]]></category>
		<category><![CDATA[Column Charts]]></category>
		<category><![CDATA[HighChart]]></category>
		<category><![CDATA[HighChart With Angular JS]]></category>
		<category><![CDATA[Line Chart]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Pie Chart]]></category>
		<category><![CDATA[Scatter Chart]]></category>
		<category><![CDATA[Server Error in Application]]></category>
		<category><![CDATA[Spline Chart]]></category>
		<category><![CDATA[The resource cannot be found]]></category>
		<category><![CDATA[Widgets With Server Side Data]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11359</guid>

					<description><![CDATA[In this article we will learn how we can create some client side chart widgets with the data from SQL Server database. We use MVC architecture with Web API and Angular JS to fetch the data and do all the manipulations. I am creating this application in Visual Studio 2015. In this project we covers topic of how to use HighChart with Angular JS. You can always get the tips/tricks/blogs about these mentioned technologies from the links given below. AngularJS Tips, Tricks, Blogs MVC Tips, Tricks, Blogs Web API Tips, Tricks, Blogs Now we will go and create our application. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will learn how we can create some client side chart widgets with the data from <a href="http://sibeeshpassion.com/category/SQL/" target="_blank" rel="noopener">SQL </a>Server database. We use MVC architecture with Web API and Angular JS to fetch the data and do all the manipulations. I am creating this application in Visual Studio 2015. In this project we covers topic of how to use <a href="http://sibeeshpassion.com/category/products/HighChart/" target="_blank" rel="noopener">HighChart </a>with Angular JS. You can always get the tips/tricks/blogs about these mentioned technologies from the links given below. </p>
<li><a href="http://sibeeshpassion.com/category/angularjs/" target="_blank" rel="noopener">AngularJS Tips, Tricks, Blogs</a></li>
<li><a href="http://sibeeshpassion.com/category/mvc/" target="_blank" rel="noopener">MVC Tips, Tricks, Blogs</a></li>
<li><a href="http://sibeeshpassion.com/category/web-api/" target="_blank" rel="noopener">Web API Tips, Tricks, Blogs</a></li>
<p>Now we will go and create our application. I hope you will like this. </p>
<p><strong>Download the source code</strong></p>
<p>You can always download the source code here.</p>
<li><a href="https://code.msdn.microsoft.com/Chart-Widgets-With-Server-70f5cdac" target="_blank" rel="noopener">Widgets With Server Side Data</a></li>
<li><a href="http://sibeeshpassion.com/Download/MyDashboardSQLScript.rar" target="_blank" rel="noopener">SQL Scripts With Insert Queries</a></li>
<p><strong>Background</strong></p>
<p>I am working now in a personal dashboard application in which I uses HighChart products for the chart integration. We can always load the chart widgets with server side data and Angular JS right? Here we will discuss that. We are going to create the preceding charts for our dashboard. </p>
<li>Pie Chart</li>
<li>Spline Chart</li>
<li>Bar Chart</li>
<li>Line Chart</li>
<li>Scatter Chart</li>
<li>Column Chart</li>
<p>Once we are done, this is how our applications output will be. </p>
<div id="attachment_11360" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chart-Widgets-With-Server-Side-Data-In-MVC-Using-Angular-JS-And-Web-API-Output-e1458121833696.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-11360" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chart-Widgets-With-Server-Side-Data-In-MVC-Using-Angular-JS-And-Web-API-Output-1024x875.png" alt="Chart Widgets With Server Side Data In MVC Using Angular JS And Web API Output" width="634" height="542" class="size-large wp-image-11360" /></a><p id="caption-attachment-11360" class="wp-caption-text">Chart Widgets With Server Side Data In MVC Using Angular JS And Web API Output</p></div>
<p><strong>Create a MVC application</strong></p>
<p>Click File-> New-> Project then select MVC application. From the following pop up we will select the template as empty and select the core references and folders for MVC. </p>
<div id="attachment_11361" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/MVC-Project-With-Empty-Template-e1458122053871.png"><img decoding="async" aria-describedby="caption-attachment-11361" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/MVC-Project-With-Empty-Template-e1458122053871.png" alt="MVC Project With Empty Template" width="650" height="508" class="size-full wp-image-11361" srcset="/wp-content/uploads/2016/03/MVC-Project-With-Empty-Template-e1458122053871.png 650w, /wp-content/uploads/2016/03/MVC-Project-With-Empty-Template-e1458122053871-300x234.png 300w, /wp-content/uploads/2016/03/MVC-Project-With-Empty-Template-e1458122053871-400x313.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11361" class="wp-caption-text">MVC Project With Empty Template</p></div>
<p>Once you click OK, a project with MVC like folder structure with core references will be created for you.</p>
<div id="attachment_11362" style="width: 277px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Folder-Structure-And-References-For-Empty-MVC-Project.png"><img decoding="async" aria-describedby="caption-attachment-11362" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Folder-Structure-And-References-For-Empty-MVC-Project.png" alt="Folder Structure And References For Empty MVC Project" width="267" height="367" class="size-full wp-image-11362" srcset="/wp-content/uploads/2016/03/Folder-Structure-And-References-For-Empty-MVC-Project.png 267w, /wp-content/uploads/2016/03/Folder-Structure-And-References-For-Empty-MVC-Project-218x300.png 218w" sizes="(max-width: 267px) 100vw, 267px" /></a><p id="caption-attachment-11362" class="wp-caption-text">Folder Structure And References For Empty MVC Project</p></div>
<p>Before going to start the coding part, make sure that all the required extensions/references are installed. Below are the required things to start with. </p>
<li>Angular JS</li>
<li>jQuery</li>
<p>You can all the items mentioned above from NuGet. Right click on your project name and select Manage NuGet packages.</p>
<div id="attachment_11235" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png"><img decoding="async" aria-describedby="caption-attachment-11235" src="http://sibeeshpassion.com/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png" alt="Manage NuGet Package Window" width="650" height="432" class="size-full wp-image-11235" srcset="/wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396.png 650w, /wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396-300x199.png 300w, /wp-content/uploads/2016/02/Manage-NuGet-Package-Window-e1455700665396-400x266.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11235" class="wp-caption-text">Manage NuGet Package Window</p></div>
<p>Once you have installed those items, please make sure that all the items(jQuery, Angular JS files) are loaded in your scripts folder. </p>
<p><strong>Using the code</strong></p>
<p>As I have said before, we are going to use Angular JS for our client side operations, so it is better to create the Angular JS script files first right? Just to make sure that we have got all the required things :). For that, create a folder named <em>Widget</em> in script folder and right click -> Add -> New Item -> Select AngularJS Module and enter the module name -> Click Add.</p>
<div id="attachment_11363" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Creating-Angular-JS-Modue-In-MVC-Application-e1458122639235.png"><img decoding="async" aria-describedby="caption-attachment-11363" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Creating-Angular-JS-Modue-In-MVC-Application-e1458122639235.png" alt="Creating Angular JS Modue In MVC Application" width="650" height="449" class="size-full wp-image-11363" srcset="/wp-content/uploads/2016/03/Creating-Angular-JS-Modue-In-MVC-Application-e1458122639235.png 650w, /wp-content/uploads/2016/03/Creating-Angular-JS-Modue-In-MVC-Application-e1458122639235-300x207.png 300w, /wp-content/uploads/2016/03/Creating-Angular-JS-Modue-In-MVC-Application-e1458122639235-160x110.png 160w, /wp-content/uploads/2016/03/Creating-Angular-JS-Modue-In-MVC-Application-e1458122639235-400x276.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11363" class="wp-caption-text">Creating Angular JS Modue In MVC Application</p></div>
<p>Follow the same procedure to create Angular JS factory and Angular JS controller. Yes, we have set everything to get started our coding. Now we will create a Web API controller and get the data from database in JSON format. Let&#8217;s start then.</p>
<p><strong>Create Web API Controller</strong></p>
<p>To create a Web API controller, just right click on your controller folder and click Add -> Controller -> Select Web API controller &#8211; Empty ( We will create our own actions later) -> Name the controller (Here I am giving the controller name as Widget).</p>
<p>So our controller is ready, now we need to set up our database so that we can create Entity Model for our application later. </p>
<p><strong>Create a database</strong></p>
<p>The following query can be used to create a database in your SQL Server.</p>
<p>[sql]<br />
USE [master]<br />
GO</p>
<p>/****** Object:  Database [TrialsDB]    Script Date: 16-Mar-16 4:08:15 PM ******/<br />
CREATE DATABASE [TrialsDB]<br />
 CONTAINMENT = NONE<br />
 ON  PRIMARY<br />
( NAME = N&#8217;TrialsDB&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB.mdf&#8217; , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )<br />
 LOG ON<br />
( NAME = N&#8217;TrialsDB_log&#8217;, FILENAME = N&#8217;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TrialsDB_log.ldf&#8217; , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET COMPATIBILITY_LEVEL = 110<br />
GO</p>
<p>IF (1 = FULLTEXTSERVICEPROPERTY(&#8216;IsFullTextInstalled&#8217;))<br />
begin<br />
EXEC [TrialsDB].[dbo].[sp_fulltext_database] @action = &#8216;enable&#8217;<br />
end<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULL_DEFAULT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_NULLS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_PADDING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ANSI_WARNINGS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ARITHABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CLOSE OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_CREATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_SHRINK OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS ON<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_CLOSE_ON_COMMIT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CURSOR_DEFAULT  GLOBAL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET CONCAT_NULL_YIELDS_NULL OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET NUMERIC_ROUNDABORT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET QUOTED_IDENTIFIER OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECURSIVE_TRIGGERS OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  DISABLE_BROKER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DATE_CORRELATION_OPTIMIZATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TRUSTWORTHY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET ALLOW_SNAPSHOT_ISOLATION OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PARAMETERIZATION SIMPLE<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET READ_COMMITTED_SNAPSHOT OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET HONOR_BROKER_PRIORITY OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET RECOVERY FULL<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  MULTI_USER<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET PAGE_VERIFY CHECKSUM<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET DB_CHAINING OFF<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET TARGET_RECOVERY_TIME = 0 SECONDS<br />
GO</p>
<p>ALTER DATABASE [TrialsDB] SET  READ_WRITE<br />
GO<br />
[/sql]</p>
<p>Now we will create the tables we needed. As of now I am going to create two tables. </p>
<li>SalesOrderDetail</li>
<li>Product</li>
<p>These tables are having relationship by the key <em>ProductID</em>.</p>
<p><strong>Create tables in database</strong></p>
<p>Below is the query to create SalesOrderDetail table in database.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>/****** Object:  Table [dbo].[SalesOrderDetail]    Script Date: 16-Mar-16 4:10:22 PM ******/<br />
SET ANSI_NULLS ON<br />
GO</p>
<p>SET QUOTED_IDENTIFIER ON<br />
GO</p>
<p>CREATE TABLE [dbo].[SalesOrderDetail](<br />
	[SalesOrderID] [int] NOT NULL,<br />
	[SalesOrderDetailID] [int] IDENTITY(1,1) NOT NULL,<br />
	[CarrierTrackingNumber] [nvarchar](25) NULL,<br />
	[OrderQty] [smallint] NOT NULL,<br />
	[ProductID] [int] NOT NULL,<br />
	[SpecialOfferID] [int] NOT NULL,<br />
	[UnitPrice] [money] NOT NULL,<br />
	[UnitPriceDiscount] [money] NOT NULL,<br />
	[LineTotal]  AS (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0))),<br />
	[rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,<br />
	[ModifiedDate] [datetime] NOT NULL,<br />
 CONSTRAINT [PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID] PRIMARY KEY CLUSTERED<br />
(<br />
	[SalesOrderID] ASC,<br />
	[SalesOrderDetailID] ASC<br />
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]<br />
) ON [PRIMARY]</p>
<p>GO<br />
[/sql]</p>
<p>Now we will create the table Product.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>/****** Object:  Table [dbo].[Product]    Script Date: 16-Mar-16 4:11:29 PM ******/<br />
SET ANSI_NULLS ON<br />
GO</p>
<p>SET QUOTED_IDENTIFIER ON<br />
GO</p>
<p>CREATE TABLE [dbo].[Product](<br />
	[ProductID] [int] NOT NULL,<br />
	[Name] [nvarchar](max) NOT NULL,<br />
	[ProductNumber] [nvarchar](25) NOT NULL,<br />
	[MakeFlag] [bit] NOT NULL,<br />
	[FinishedGoodsFlag] [bit] NOT NULL,<br />
	[Color] [nvarchar](15) NULL,<br />
	[SafetyStockLevel] [smallint] NOT NULL,<br />
	[ReorderPoint] [smallint] NOT NULL,<br />
	[StandardCost] [money] NOT NULL,<br />
	[ListPrice] [money] NOT NULL,<br />
	[Size] [nvarchar](5) NULL,<br />
	[SizeUnitMeasureCode] [nchar](3) NULL,<br />
	[WeightUnitMeasureCode] [nchar](3) NULL,<br />
	[Weight] [decimal](8, 2) NULL,<br />
	[DaysToManufacture] [int] NOT NULL,<br />
	[ProductLine] [nchar](2) NULL,<br />
	[Class] [nchar](2) NULL,<br />
	[Style] [nchar](2) NULL,<br />
	[ProductSubcategoryID] [int] NULL,<br />
	[ProductModelID] [int] NULL,<br />
	[SellStartDate] [datetime] NOT NULL,<br />
	[SellEndDate] [datetime] NULL,<br />
	[DiscontinuedDate] [datetime] NULL,<br />
	[rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,<br />
	[ModifiedDate] [datetime] NOT NULL<br />
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]</p>
<p>GO<br />
[/sql]</p>
<p>Can we insert some data to the tables now?</p>
<p><strong>Insert data to table</strong></p>
<p>You can use the below query to insert the data to SalesOrderDetail.</p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>INSERT INTO [dbo].[SalesOrderDetail]<br />
           ([SalesOrderID]<br />
           ,[CarrierTrackingNumber]<br />
           ,[OrderQty]<br />
           ,[ProductID]<br />
           ,[SpecialOfferID]<br />
           ,[UnitPrice]<br />
           ,[UnitPriceDiscount]<br />
           ,[rowguid]<br />
           ,[ModifiedDate])<br />
     VALUES<br />
           (&lt;SalesOrderID, int,&gt;<br />
           ,&lt;CarrierTrackingNumber, nvarchar(25),&gt;<br />
           ,&lt;OrderQty, smallint,&gt;<br />
           ,&lt;ProductID, int,&gt;<br />
           ,&lt;SpecialOfferID, int,&gt;<br />
           ,&lt;UnitPrice, money,&gt;<br />
           ,&lt;UnitPriceDiscount, money,&gt;<br />
           ,&lt;rowguid, uniqueidentifier,&gt;<br />
           ,&lt;ModifiedDate, datetime,&gt;)<br />
GO<br />
[/sql]</p>
<p>and the following query can be used for the table <em>Product</em></p>
<p>[sql]<br />
USE [TrialsDB]<br />
GO</p>
<p>INSERT INTO [dbo].[Product]<br />
           ([ProductID]<br />
           ,[Name]<br />
           ,[ProductNumber]<br />
           ,[MakeFlag]<br />
           ,[FinishedGoodsFlag]<br />
           ,[Color]<br />
           ,[SafetyStockLevel]<br />
           ,[ReorderPoint]<br />
           ,[StandardCost]<br />
           ,[ListPrice]<br />
           ,[Size]<br />
           ,[SizeUnitMeasureCode]<br />
           ,[WeightUnitMeasureCode]<br />
           ,[Weight]<br />
           ,[DaysToManufacture]<br />
           ,[ProductLine]<br />
           ,[Class]<br />
           ,[Style]<br />
           ,[ProductSubcategoryID]<br />
           ,[ProductModelID]<br />
           ,[SellStartDate]<br />
           ,[SellEndDate]<br />
           ,[DiscontinuedDate]<br />
           ,[rowguid]<br />
           ,[ModifiedDate])<br />
     VALUES<br />
           (&lt;ProductID, int,&gt;<br />
           ,&lt;Name, nvarchar(max),&gt;<br />
           ,&lt;ProductNumber, nvarchar(25),&gt;<br />
           ,&lt;MakeFlag, bit,&gt;<br />
           ,&lt;FinishedGoodsFlag, bit,&gt;<br />
           ,&lt;Color, nvarchar(15),&gt;<br />
           ,&lt;SafetyStockLevel, smallint,&gt;<br />
           ,&lt;ReorderPoint, smallint,&gt;<br />
           ,&lt;StandardCost, money,&gt;<br />
           ,&lt;ListPrice, money,&gt;<br />
           ,&lt;Size, nvarchar(5),&gt;<br />
           ,&lt;SizeUnitMeasureCode, nchar(3),&gt;<br />
           ,&lt;WeightUnitMeasureCode, nchar(3),&gt;<br />
           ,&lt;Weight, decimal(8,2),&gt;<br />
           ,&lt;DaysToManufacture, int,&gt;<br />
           ,&lt;ProductLine, nchar(2),&gt;<br />
           ,&lt;Class, nchar(2),&gt;<br />
           ,&lt;Style, nchar(2),&gt;<br />
           ,&lt;ProductSubcategoryID, int,&gt;<br />
           ,&lt;ProductModelID, int,&gt;<br />
           ,&lt;SellStartDate, datetime,&gt;<br />
           ,&lt;SellEndDate, datetime,&gt;<br />
           ,&lt;DiscontinuedDate, datetime,&gt;<br />
           ,&lt;rowguid, uniqueidentifier,&gt;<br />
           ,&lt;ModifiedDate, datetime,&gt;)<br />
GO<br />
[/sql] </p>
<p>So let us say, we have inserted the data as follows. If you feel bored of inserting data manually, you can always tun the SQL script file attached which has the insertion queries. Just run that, you will be all OK. If you don&#8217;t know how to generate SQL scripts with data, I strongly recommend you to have a read <a href="http://sibeeshpassion.com/generate-database-scripts-with-data-in-sql-server/" target="_blank" rel="noopener">here</a></p>
<p>Next thing we are going to do is creating a ADO.NET Entity Data Model. </p>
<p><strong>Create Entity Data Model</strong></p>
<p>Right click on your model folder and click new, select ADO.NET Entity Data Model. Follow the steps given. Once you have done the processes, you can see the edmx file and other files in your model folder. Here I gave <em>Dashboard</em> for our Entity data model name. Now you can see a file with edmx extension have been created. If you open that file, you can see as below. </p>
<div id="attachment_11364" style="width: 513px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Entity-Data-Model.png"><img decoding="async" aria-describedby="caption-attachment-11364" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Entity-Data-Model.png" alt="Entity Data Model" width="503" height="669" class="size-full wp-image-11364" srcset="/wp-content/uploads/2016/03/Entity-Data-Model.png 503w, /wp-content/uploads/2016/03/Entity-Data-Model-226x300.png 226w, /wp-content/uploads/2016/03/Entity-Data-Model-400x532.png 400w, /wp-content/uploads/2016/03/Entity-Data-Model-451x600.png 451w" sizes="(max-width: 503px) 100vw, 503px" /></a><p id="caption-attachment-11364" class="wp-caption-text">Entity Data Model</p></div>
<p>Now go back our Web API controller. Please change the code as below.</p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Net.Http;<br />
using System.Web.Http;<br />
using MyDashboard.Models;<br />
using Newtonsoft.Json;<br />
namespace MyDashboard.Controllers<br />
{<br />
    public class WidgetController : ApiController<br />
    {<br />
        public DashboardEntities de = new DashboardEntities();<br />
        Retriever ret = new Retriever();<br />
        public string getWidgetData()<br />
        {<br />
            var dataList = ret.GetWidgetData(de);<br />
            return dataList;<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Here we have created a new model class <em>Retriever </em> and we have added a method <em>GetWidgetData</em> in that class. Now let us see what I have coded in that.</p>
<p>[csharp]<br />
using Newtonsoft.Json;<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;</p>
<p>namespace MyDashboard.Models<br />
{<br />
    public class Retriever<br />
    {<br />
        public string GetWidgetData(DashboardEntities de)<br />
        {<br />
            try<br />
            {<br />
                using (de)<br />
                {<br />
                    var resList = (from sales in de.SalesOrderDetails<br />
                                  join prod in de.Products<br />
                                  on sales.ProductID equals prod.ProductID<br />
                                  select new<br />
                                  {<br />
                                      ProductName = prod.Name,<br />
                                      QuantityOrdered = sales.OrderQty<br />
                                  });<br />
                    var res = resList.GroupBy(d =&gt; d.ProductName).Select(g =&gt; new<br />
                    {<br />
                        name = g.FirstOrDefault().ProductName,<br />
                        y = g.Sum(s =&gt; s.QuantityOrdered)<br />
                    });<br />
                    return JsonConvert.SerializeObject(res, Formatting.None, new JsonSerializerSettings()<br />
                    {<br />
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore<br />
                    });<br />
                }<br />
            }<br />
            catch (Exception)<br />
            {<br />
                throw new NotImplementedException();<br />
            }</p>
<p>        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Here we are using LINQ to fetch the data, We uses JOIN in the query to find the <em>Name </em> from the table Products. Once the data is ready, we are just do group by the column <em>ProductName</em> and sum of <em>QuantityOrdered</em>. </p>
<p>[csharp]<br />
var res = resList.GroupBy(d =&gt; d.ProductName).Select(g =&gt; new<br />
                    {<br />
                        name = g.FirstOrDefault().ProductName,<br />
                        y = g.Sum(s =&gt; s.QuantityOrdered)<br />
                    });<br />
[/csharp]</p>
<p>So the coding part to fetch the data from database is read, now we need to check whether our Web API is ready for action!. To check that, you just need to run the URL <em>http://localhost:1646/Api/Widget</em>. Here <em>Widget</em> is our Web API controller name. I hope you get the data as a result. If you are getting the error <em>Server Error in &#8216;/&#8217; Application The resource cannot be found</em>, you need to configure your Web API in <em>Global.asax.cs</em>. You got this error just because you created an Empty project with only needed references. So here we need to do his step by our own. No worries, we will do it now. Just change the <em>Global.asax.cs </em>as follows. </p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Http;<br />
using System.Web.Mvc;<br />
using System.Web.Routing;</p>
<p>namespace MyDashboard<br />
{<br />
    public class MvcApplication : System.Web.HttpApplication<br />
    {<br />
        protected void Application_Start()<br />
        {<br />
            AreaRegistration.RegisterAllAreas();<br />
            GlobalConfiguration.Configure(WebApiConfig.Register);//This is for setting the configuration<br />
            RouteConfig.RegisterRoutes(RouteTable.Routes);<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Now build your application and run the same URL again, you will get the output as follows. </p>
<div id="attachment_11365" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Web-API-Output.png"><img decoding="async" aria-describedby="caption-attachment-11365" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Web-API-Output-1024x258.png" alt="Web API Output" width="634" height="160" class="size-large wp-image-11365" srcset="/wp-content/uploads/2016/03/Web-API-Output-1024x258.png 1024w, /wp-content/uploads/2016/03/Web-API-Output-300x75.png 300w, /wp-content/uploads/2016/03/Web-API-Output-768x193.png 768w, /wp-content/uploads/2016/03/Web-API-Output-400x101.png 400w, /wp-content/uploads/2016/03/Web-API-Output.png 1367w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11365" class="wp-caption-text">Web API Output</p></div>
<p>Now we will go back to our angular JS files and consume this Web API. You need to change the scripts in the <em>app.js, controller.js, factory.js</em> as follows.</p>
<p><strong>app.js</strong></p>
<p>[js]<br />
(function () {<br />
    &#8216;use strict&#8217;;<br />
    angular.module(&#8216;WidgetsApp&#8217;, []);<br />
})();<br />
[/js]</p>
<p><strong>controller.js</strong></p>
<p>[js]<br />
(function () {<br />
    &#8216;use strict&#8217;;<br />
    angular<br />
        .module(&#8216;WidgetsApp&#8217;)<br />
        .controller(&#8216;WidgetsController&#8217;, function ($scope, factory) {<br />
            var res = factory.getData();<br />
            var options;<br />
            if (res != undefined) {<br />
                res.then(function (d) {<br />
                    var data = JSON.parse(d.data);</p>
<p>                }, function (error) {<br />
                    console.log(&#8216;Oops! Something went wrong while fetching the data.&#8217;);<br />
                });<br />
            }<br />
        });<br />
})();</p>
<p>[/js]</p>
<p>Once our service is called, we will get the data in return. We will parse the same and store it in a variable for future use.</p>
<p>[js]<br />
var data = JSON.parse(d.data);<br />
[/js]</p>
<p><strong>factory.js</strong></p>
<p>[js]<br />
(function () {<br />
    &#8216;use strict&#8217;;<br />
    angular<br />
        .module(&#8216;WidgetsApp&#8217;)<br />
        .service(&#8216;factory&#8217;, function ($http) {<br />
            this.getData = function () {<br />
                var url = &#8216;Api/Widget&#8217;;<br />
                return $http({<br />
                    type: &#8216;get&#8217;,<br />
                    url: url<br />
                });<br />
            }<br />
        });<br />
})();<br />
[/js]</p>
<p>AS you can see we are just calling our Web API <em>Api/Widget</em> with the help of <a href="http://sibeeshpassion.com/learning-angularjs-http/" target="_blank" rel="noopener">Angular $http.</a></p>
<p>Now we a view to show our data right? Yes, we need a controller too!.</p>
<p><strong>Create a MVC controller</strong></p>
<p>To create a controller, we need to right click on the controller folder, Add &#8211; Controller. I hope you will be given a controller as follows. </p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Mvc;</p>
<p>namespace MyDashboard.Controllers<br />
{<br />
    public class HomeController : Controller<br />
    {<br />
        // GET: Home<br />
        public ActionResult Index()<br />
        {<br />
            return View();<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Here <em>Home</em> is our controller name. </p>
<p>Now we need a view right?</p>
<p><strong>Creating a view</strong></p>
<p>To create a view, just right click on your controller name -> Add View -> Add.</p>
<div id="attachment_11366" style="width: 635px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Creating-a-view.png"><img decoding="async" aria-describedby="caption-attachment-11366" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Creating-a-view.png" alt="Creating a view" width="625" height="398" class="size-full wp-image-11366" srcset="/wp-content/uploads/2016/03/Creating-a-view.png 625w, /wp-content/uploads/2016/03/Creating-a-view-300x191.png 300w, /wp-content/uploads/2016/03/Creating-a-view-400x255.png 400w" sizes="(max-width: 625px) 100vw, 625px" /></a><p id="caption-attachment-11366" class="wp-caption-text">Creating a view</p></div>
<p>Now in your view add the needed references.</p>
<p>[html]<br />
&lt;script src=&quot;~/scripts/jquery-1.10.2.min.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/jquery-ui-1.11.4.min.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/angular.min.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/angular-aria.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/angular-route.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/Widgets/app.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/Widgets/controller.js&quot;&gt;&lt;/script&gt;<br />
&lt;script src=&quot;~/scripts/Widgets/factory.js&quot;&gt;&lt;/script&gt;<br />
[/html]</p>
<p>Once we add the references, we can call our Angular JS controller as follows.</p>
<p>[html]<br />
&lt;div ng-app=&quot;WidgetsApp&quot;&gt;<br />
    &lt;div ng-controller=&quot;WidgetsController&quot;&gt;<br />
    &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>Now if you run your application, you can see our Web API call works fine and successfully get the data. Next thing we need to do is creating charts with the data we get.</p>
<p><strong>Create chart widgets with the data</strong></p>
<p>As I said, we are going to to create HighChart chart widgets, we need to add a reference to use that plug in.</p>
<p>[html]<br />
&lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;<br />
[/html]</p>
<p>Now create elements where we can load our chart.</p>
<p>[html]<br />
&lt;div ng-app=&quot;WidgetsApp&quot;&gt;<br />
    &lt;div ng-controller=&quot;WidgetsController&quot;&gt;<br />
        &lt;div id=&quot;widgetPie&quot; class=&quot;widget&quot;&gt;Placeholder for chart&lt;/div&gt;<br />
        &lt;div id=&quot;widgetspline&quot; class=&quot;widget&quot;&gt;Placeholder for chart&lt;/div&gt;<br />
        &lt;div id=&quot;widgetBar&quot; class=&quot;widget&quot;&gt;Placeholder for chart&lt;/div&gt;<br />
        &lt;div id=&quot;widgetLine&quot; class=&quot;widget&quot;&gt;Placeholder for chart&lt;/div&gt;<br />
        &lt;div id=&quot;widgetScatter&quot; class=&quot;widget&quot;&gt;Placeholder for chart&lt;/div&gt;<br />
        &lt;div id=&quot;widgetColumn&quot; class=&quot;widget&quot;&gt;Placeholder for chart&lt;/div&gt;<br />
    &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>You can style your elements as follows if you want, but this is optional.</p>
<p>[css]<br />
&lt;style&gt;<br />
    .widget {<br />
        width: 30%;<br />
        border: 1px solid #ccc;<br />
        padding: 10px;<br />
        margin: 5px;<br />
        border-radius: 3px;<br />
        transition: none;<br />
        -webkit-transition: none;<br />
        -moz-transition: none;<br />
        -o-transition: none;<br />
        cursor: move;<br />
        display: inline-block;<br />
        float:left;<br />
    }<br />
&lt;/style&gt;<br />
[/css]</p>
<p>Go back to our Angular JS controller and add the below codes right after we get the data from server. </p>
<p><strong>Pie Chart</strong></p>
<p>[js]<br />
var data = JSON.parse(d.data);<br />
                    var categories = [];<br />
                    for (var i = 0; i &lt; data.length; i++) {<br />
                        categories.push(data[i].name)<br />
                    }<br />
                    options = new Highcharts.chart(&#8216;widgetPie&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;pie&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Pie Chart&#8217;<br />
                        },<br />
                        plotOptions: {<br />
                            pie: {<br />
                                allowPointSelect: true,<br />
                                cursor: &#8216;pointer&#8217;,<br />
                                dataLabels: {<br />
                                    enabled: false,<br />
                                    format: &#8216;&lt;b&gt;{point.name}&lt;/b&gt;: {point.y:,.0f}&#8217;<br />
                                }<br />
                            }<br />
                        },<br />
                        series: [{<br />
                            name:&#8217;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
[/js]</p>
<p>Now run your application, you can see a pie chart with the data given. </p>
<div id="attachment_11368" style="width: 358px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Pie-Chart-In-MVC-With-Angular-JS-And-Web-API.png"><img decoding="async" aria-describedby="caption-attachment-11368" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Pie-Chart-In-MVC-With-Angular-JS-And-Web-API.png" alt="Pie Chart In MVC With Angular JS And Web API" width="348" height="427" class="size-full wp-image-11368" srcset="/wp-content/uploads/2016/03/Pie-Chart-In-MVC-With-Angular-JS-And-Web-API.png 348w, /wp-content/uploads/2016/03/Pie-Chart-In-MVC-With-Angular-JS-And-Web-API-244x300.png 244w" sizes="(max-width: 348px) 100vw, 348px" /></a><p id="caption-attachment-11368" class="wp-caption-text">Pie Chart In MVC With Angular JS And Web API</p></div>
<p><strong>Column Chart</strong></p>
<p>[js]<br />
options = new Highcharts.chart(&#8216;widgetColumn&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;column&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Column Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
[/js]</p>
<p>Now run your application, you can see a column chart with the data given. </p>
<div id="attachment_11369" style="width: 364px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Column-Chart-In-MVC-With-Angular-JS-And-Web-API.png"><img decoding="async" aria-describedby="caption-attachment-11369" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Column-Chart-In-MVC-With-Angular-JS-And-Web-API.png" alt="Column Chart In MVC With Angular JS And Web API" width="354" height="433" class="size-full wp-image-11369" srcset="/wp-content/uploads/2016/03/Column-Chart-In-MVC-With-Angular-JS-And-Web-API.png 354w, /wp-content/uploads/2016/03/Column-Chart-In-MVC-With-Angular-JS-And-Web-API-245x300.png 245w" sizes="(max-width: 354px) 100vw, 354px" /></a><p id="caption-attachment-11369" class="wp-caption-text">Column Chart In MVC With Angular JS And Web API</p></div>
<p><strong>Bar Chart</strong></p>
<p>[js]<br />
options = new Highcharts.chart(&#8216;widgetBar&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;bar&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Bar Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
[/js]</p>
<p>Now run your application, you can see a Bar chart with the data given. </p>
<div id="attachment_11370" style="width: 362px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Bar-Chart-In-MVC-With-Angular-JS-And-Web-API.png"><img decoding="async" aria-describedby="caption-attachment-11370" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Bar-Chart-In-MVC-With-Angular-JS-And-Web-API.png" alt="Bar Chart In MVC With Angular JS And Web API" width="352" height="431" class="size-full wp-image-11370" srcset="/wp-content/uploads/2016/03/Bar-Chart-In-MVC-With-Angular-JS-And-Web-API.png 352w, /wp-content/uploads/2016/03/Bar-Chart-In-MVC-With-Angular-JS-And-Web-API-245x300.png 245w" sizes="(max-width: 352px) 100vw, 352px" /></a><p id="caption-attachment-11370" class="wp-caption-text">Bar Chart In MVC With Angular JS And Web API</p></div>
<p><strong>Line Chart</strong></p>
<p>[js]<br />
options = new Highcharts.chart(&#8216;widgetLine&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;line&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Line Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
[/js]</p>
<p>Now run your application, you can see a Line chart with the data given. </p>
<div id="attachment_11371" style="width: 364px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Line-Chart-In-MVC-With-Angular-JS-And-Web-API.png"><img decoding="async" aria-describedby="caption-attachment-11371" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Line-Chart-In-MVC-With-Angular-JS-And-Web-API.png" alt="Line Chart In MVC With Angular JS And Web API" width="354" height="436" class="size-full wp-image-11371" srcset="/wp-content/uploads/2016/03/Line-Chart-In-MVC-With-Angular-JS-And-Web-API.png 354w, /wp-content/uploads/2016/03/Line-Chart-In-MVC-With-Angular-JS-And-Web-API-244x300.png 244w" sizes="(max-width: 354px) 100vw, 354px" /></a><p id="caption-attachment-11371" class="wp-caption-text">Line Chart In MVC With Angular JS And Web API</p></div>
<p><strong>Spline Chart</strong></p>
<p>[js]<br />
options = new Highcharts.chart(&#8216;widgetspline&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;spline&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Spline Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
[/js]</p>
<p>Now run your application, you can see a Spline chart with the data given. </p>
<div id="attachment_11372" style="width: 363px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Spline-Chart-In-MVC-With-Angular-JS-And-Web-API.png"><img decoding="async" aria-describedby="caption-attachment-11372" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Spline-Chart-In-MVC-With-Angular-JS-And-Web-API.png" alt="Spline Chart In MVC With Angular JS And Web API" width="353" height="432" class="size-full wp-image-11372" srcset="/wp-content/uploads/2016/03/Spline-Chart-In-MVC-With-Angular-JS-And-Web-API.png 353w, /wp-content/uploads/2016/03/Spline-Chart-In-MVC-With-Angular-JS-And-Web-API-245x300.png 245w" sizes="(max-width: 353px) 100vw, 353px" /></a><p id="caption-attachment-11372" class="wp-caption-text">Spline Chart In MVC With Angular JS And Web API</p></div>
<p><strong>Scatter Chart</strong></p>
<p>[js]<br />
 options = new Highcharts.chart(&#8216;widgetScatter&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;scatter&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Scatter Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
[/js]</p>
<p>Now run your application, you can see a Scatter chart with the data given. </p>
<div id="attachment_11374" style="width: 361px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Scatter-Chart-In-MVC-With-Angular-JS-And-Web-API.png"><img decoding="async" aria-describedby="caption-attachment-11374" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Scatter-Chart-In-MVC-With-Angular-JS-And-Web-API.png" alt="Scatter Chart In MVC With Angular JS And Web API" width="351" height="432" class="size-full wp-image-11374" srcset="/wp-content/uploads/2016/03/Scatter-Chart-In-MVC-With-Angular-JS-And-Web-API.png 351w, /wp-content/uploads/2016/03/Scatter-Chart-In-MVC-With-Angular-JS-And-Web-API-244x300.png 244w" sizes="(max-width: 351px) 100vw, 351px" /></a><p id="caption-attachment-11374" class="wp-caption-text">Scatter Chart In MVC With Angular JS And Web API</p></div>
<p>Now this is how complete code for our controller.js file looks like. </p>
<p>[js]<br />
(function () {<br />
    &#8216;use strict&#8217;;<br />
    angular<br />
        .module(&#8216;WidgetsApp&#8217;)<br />
        .controller(&#8216;WidgetsController&#8217;, function ($scope, factory) {<br />
            var res = factory.getData();<br />
            var options;<br />
            if (res != undefined) {<br />
                res.then(function (d) {<br />
                    var data = JSON.parse(d.data);<br />
                    var categories = [];<br />
                    for (var i = 0; i &lt; data.length; i++) {<br />
                        categories.push(data[i].name)<br />
                    }<br />
                    options = new Highcharts.chart(&#8216;widgetPie&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;pie&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Pie Chart&#8217;<br />
                        },<br />
                        plotOptions: {<br />
                            pie: {<br />
                                allowPointSelect: true,<br />
                                cursor: &#8216;pointer&#8217;,<br />
                                dataLabels: {<br />
                                    enabled: false,<br />
                                    format: &#8216;&lt;b&gt;{point.name}&lt;/b&gt;: {point.y:,.0f}&#8217;<br />
                                }<br />
                            }<br />
                        },<br />
                        series: [{<br />
                            name:&#8217;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
                    options = new Highcharts.chart(&#8216;widgetColumn&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;column&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Column Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
                    options = new Highcharts.chart(&#8216;widgetBar&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;bar&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Bar Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
                    options = new Highcharts.chart(&#8216;widgetLine&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;line&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Line Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
                    options = new Highcharts.chart(&#8216;widgetspline&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;spline&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Spline Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
                    options = new Highcharts.chart(&#8216;widgetScatter&#8217;, {<br />
                        credits: {<br />
                            enabled: false<br />
                        },<br />
                        chart: {<br />
                            type: &#8216;scatter&#8217;,<br />
                            renderTo: &#8221;<br />
                        },<br />
                        title: {<br />
                            text: &#8216;Product VS Quantity &#8211; Scatter Chart&#8217;<br />
                        },<br />
                        series: [{<br />
                            name: &#8216;Quantity&#8217;,<br />
                            data: data<br />
                        }]<br />
                    });<br />
                }, function (error) {<br />
                    console.log(&#8216;Oops! Something went wrong while fetching the data.&#8217;);<br />
                });<br />
            }<br />
        });<br />
})();<br />
[/js]</p>
<p>If you have configured all the chart types, we can see the output now 🙂</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chart-Widgets-In-MVC-With-Angular-JS-And-Web-API-e1458191984345.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chart-Widgets-In-MVC-With-Angular-JS-And-Web-API-1024x907.png" alt="Chart Widgets In MVC With Angular JS And Web API" width="634" height="562" class="alignnone size-large wp-image-11375" /></a></p>
<p>We have done everything!. That&#8217;s fantastic right? Have a happy coding.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Did you try Web API yet? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/chart-widgets-with-server-side-data-in-mvc-using-angular-js-and-web-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Working With Charts Using Spire.XLS</title>
		<link>https://www.sibeeshpassion.com/working-with-charts-using-spire-xls/</link>
					<comments>https://www.sibeeshpassion.com/working-with-charts-using-spire-xls/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 11 Aug 2015 15:45:19 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Spire.XLS]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[Charts Using Spire.XLS]]></category>
		<category><![CDATA[Column Charts]]></category>
		<category><![CDATA[Pie Charts]]></category>
		<category><![CDATA[Save Excel Charts as Images]]></category>
		<category><![CDATA[Spire.XLs]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=8751</guid>

					<description><![CDATA[Today we are going to see an another series of new product Spire.XLS which helps us to create, manipulate, convert EXCEL file to other formats, create charts dynamically and many more. This product has been introduced by the company E-Iceblue. I hope you have read my article of Spire.Doc and Spire.XLS. If you have not read it, I recommend you to read it here: Using Spire.XLS Background As you all know, charts are the graphical representations of our data. It is much easier to understand our data if it is in a graphical form. Am I right? It is easy [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Today we are going to see an another series of new product <em>Spire.XLS</em> which helps us to create, manipulate, convert EXCEL file to other formats, create charts dynamically and many more. This product has been introduced by the company <a href="http://www.e-iceblue.com/" target="_blank" rel="noopener">E-Iceblue</a>. I hope you have read my article of <em>Spire.Doc</em> and <em>Spire.XLS</em>. If you have not read it, I recommend you to read it here: <a href="http://sibeeshpassion.com/using-spire-xls/" target="_blank" rel="noopener">Using Spire.XLS</a></p>
<p><strong>Background</strong></p>
<p>As you all know, charts are the graphical representations of our data. It is much easier to understand our data if it is in a graphical form. Am I right? It is easy to create a static chart, but what about a dynamic one? It will be bit tough right? But by using Spire.XLS, we can create any kind of charts easily. In this post, we will see those implementations. </p>
<p><strong>Download the files</strong></p>
<p>You can always get the needed files from here: <a href="http://www.e-iceblue.com/Download/download-excel-for-net-now.html" target="_blank" rel="noopener">Download Spire.XLS</a></p>
<p><strong>Install Spire.XLS</strong></p>
<p>I am using evaluation version with one month temporary license. There are free versions also available for spire.xls with some limitation. You can try that. Now click on the exe file after you extract the downloaded file. The installation will get started then.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/InstallSpireXls.png" alt="Using Spire XLS" /></p>
<p><strong>Using the code</strong></p>
<p>Before starting with coding you need to add the needed namespaces as follows.</p>
<p>[csharp]<br />
using Spire.Xls;<br />
using System.Drawing;<br />
[/csharp]</p>
<p>First of all create a form and then a button, in the button click add the following lines of codes.</p>
<p><strong>C# Code</strong></p>
<p>[csharp]<br />
  private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                //Create a new workbook<br />
                Workbook workbook = new Workbook();<br />
                //Initialize worksheet<br />
                workbook.CreateEmptySheets(1);<br />
                Worksheet sheet = workbook.Worksheets[0];<br />
                //Set sheet name<br />
                sheet.Name = &quot;Chart data&quot;;<br />
                //Set the grid lines invisible<br />
                sheet.GridLinesVisible = false;<br />
                //Create a chart<br />
                Chart chart = sheet.Charts.Add(ExcelChartType.Pie3D);<br />
                //Set region of chart data<br />
                chart.DataRange = sheet.Range[&quot;B2:B5&quot;];<br />
                chart.SeriesDataFromRange = false;<br />
                //Set position of chart<br />
                chart.LeftColumn = 1;<br />
                chart.TopRow = 6;<br />
                chart.RightColumn = 9;<br />
                chart.BottomRow = 25;<br />
                //Chart title<br />
                chart.ChartTitle = &quot;Sales by year&quot;;<br />
                chart.ChartTitleArea.IsBold = true;<br />
                chart.ChartTitleArea.Size = 12;<br />
                //Initialize the chart series<br />
                Spire.Xls.Charts.ChartSerie cs = chart.Series[0];<br />
                //Chart Labels resource<br />
                cs.CategoryLabels = sheet.Range[&quot;A2:A5&quot;];<br />
                //Chart value resource<br />
                cs.Values = sheet.Range[&quot;B2:B5&quot;];<br />
                //Set the value visible in the chart<br />
                cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;<br />
                //Year<br />
                sheet.Range[&quot;A1&quot;].Value = &quot;Year&quot;;<br />
                sheet.Range[&quot;A2&quot;].Value = &quot;2002&quot;;<br />
                sheet.Range[&quot;A3&quot;].Value = &quot;2003&quot;;<br />
                sheet.Range[&quot;A4&quot;].Value = &quot;2004&quot;;<br />
                sheet.Range[&quot;A5&quot;].Value = &quot;2005&quot;;<br />
                //Sales<br />
                sheet.Range[&quot;B1&quot;].Value = &quot;Sales&quot;;<br />
                sheet.Range[&quot;B2&quot;].NumberValue = 4000;<br />
                sheet.Range[&quot;B3&quot;].NumberValue = 6000;<br />
                sheet.Range[&quot;B4&quot;].NumberValue = 7000;<br />
                sheet.Range[&quot;B5&quot;].NumberValue = 8500;<br />
                //Style<br />
                sheet.Range[&quot;A1:B1&quot;].Style.Font.IsBold = true;<br />
                sheet.Range[&quot;A2:B2&quot;].Style.KnownColor = ExcelColors.LightYellow;<br />
                sheet.Range[&quot;A3:B3&quot;].Style.KnownColor = ExcelColors.LightGreen1;<br />
                sheet.Range[&quot;A4:B4&quot;].Style.KnownColor = ExcelColors.LightOrange;<br />
                sheet.Range[&quot;A5:B5&quot;].Style.KnownColor = ExcelColors.LightTurquoise;<br />
                //Border<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;<br />
                //Number format<br />
                sheet.Range[&quot;B2:C5&quot;].Style.NumberFormat = &quot;\&quot;$\&quot;#,##0&quot;;<br />
                chart.PlotArea.Fill.Visible = false;<br />
                //Save the file<br />
                workbook.SaveToFile(&quot;Sample.xls&quot;);<br />
                //Launch the file<br />
                System.Diagnostics.Process.Start(&quot;Sample.xls&quot;);<br />
            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p><strong>VB.NET Code</strong></p>
<p>[vb]<br />
 &#8216;Create a new workbook<br />
        Dim workbook As New Workbook()<br />
        &#8216;Initialize worksheet<br />
        workbook.CreateEmptySheets(1)<br />
        Dim sheet As Worksheet = workbook.Worksheets(0)<br />
        &#8216;Set sheet name<br />
        sheet.Name = &quot;Chart data&quot;<br />
        &#8216;Set the grid lines invisible<br />
        sheet.GridLinesVisible = False<br />
        &#8216;Create a chart<br />
        Dim chart As Chart = sheet.Charts.Add(ExcelChartType.Pie3D)<br />
        &#8216;Set region of chart data<br />
        chart.DataRange = sheet.Range(&quot;B2:B5&quot;)<br />
        chart.SeriesDataFromRange = False<br />
        &#8216;Set position of chart<br />
        chart.LeftColumn = 1<br />
        chart.TopRow = 6<br />
        chart.RightColumn = 9<br />
        chart.BottomRow = 25<br />
        &#8216;Chart title<br />
        chart.ChartTitle = &quot;Sales by year&quot;<br />
        chart.ChartTitleArea.IsBold = True<br />
        chart.ChartTitleArea.Size = 12<br />
        &#8216;Set the chart<br />
        Dim cs As Spire.Xls.Charts.ChartSerie = chart.Series(0)<br />
        &#8216;Chart Labels resource<br />
        cs.CategoryLabels = sheet.Range(&quot;A2:A5&quot;)<br />
        &#8216;Chart value resource<br />
        cs.Values = sheet.Range(&quot;B2:B5&quot;)<br />
        &#8216;Set the value visible in the chart<br />
        cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = True<br />
        &#8216;Year<br />
        sheet.Range(&quot;A1&quot;).Value = &quot;Year&quot;<br />
        sheet.Range(&quot;A2&quot;).Value = &quot;2002&quot;<br />
        sheet.Range(&quot;A3&quot;).Value = &quot;2003&quot;<br />
        sheet.Range(&quot;A4&quot;).Value = &quot;2004&quot;<br />
        sheet.Range(&quot;A5&quot;).Value = &quot;2005&quot;<br />
        &#8216;Sales<br />
        sheet.Range(&quot;B1&quot;).Value = &quot;Sales&quot;<br />
        sheet.Range(&quot;B2&quot;).NumberValue = 4000<br />
        sheet.Range(&quot;B3&quot;).NumberValue = 6000<br />
        sheet.Range(&quot;B4&quot;).NumberValue = 7000<br />
        sheet.Range(&quot;B5&quot;).NumberValue = 8500<br />
        &#8216;Style<br />
        sheet.Range(&quot;A1:B1&quot;).Style.Font.IsBold = True<br />
        sheet.Range(&quot;A2:B2&quot;).Style.KnownColor = ExcelColors.LightYellow<br />
        sheet.Range(&quot;A3:B3&quot;).Style.KnownColor = ExcelColors.LightGreen1<br />
        sheet.Range(&quot;A4:B4&quot;).Style.KnownColor = ExcelColors.LightOrange<br />
        sheet.Range(&quot;A5:B5&quot;).Style.KnownColor = ExcelColors.LightTurquoise<br />
        &#8216;Border<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeTop).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeTop).LineStyle = LineStyleType.Thin<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeBottom).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeBottom).LineStyle = LineStyleType.Thin<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeLeft).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeLeft).LineStyle = LineStyleType.Thin<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeRight).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeRight).LineStyle = LineStyleType.Thin<br />
        &#8216;Number format<br />
        sheet.Range(&quot;B2:C5&quot;).Style.NumberFormat = &quot;&quot;&quot;$&quot;&quot;#,##0&quot;<br />
        chart.PlotArea.Fill.Visible = False<br />
        &#8216;Save doc file.<br />
        workbook.SaveToFile(&quot;Sample.xls&quot;)<br />
        &#8216;Launch the MS Word file.<br />
        System.Diagnostics.Process.Start(&quot;Sample.xls&quot;)<br />
[/vb]</p>
<p>In the above lines code, we are creating a pie chart by giving some settings and data and load it. Now if you run you will get an output as follows.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541.png" alt="Create_Charts_Using_SpireXLS" width="650" height="261" class="alignnone size-full wp-image-8761" srcset="/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541.png 650w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541-300x120.png 300w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541-400x161.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output.png" alt="Create_Charts_Using_SpireXLS_Output" width="581" height="510" class="alignnone size-full wp-image-8771" srcset="/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output.png 581w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output-300x263.png 300w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output-400x351.png 400w" sizes="(max-width: 581px) 100vw, 581px" /></a></p>
<p>In the above mentioned lines of codes, we are doing so many processes, those processes are listed below.</p>
<li>Creating a new workbook</li>
<li>Initialize worksheet newly created</li>
<li>Set sheet name of worksheet</li>
<li>Set the grid lines invisible</li>
<li>Creating a chart</li>
<li>Set region of chart data</li>
<li>Set position of chart</li>
<li>Set Chart title</li>
<li>Initialize the chart series</li>
<li>Setting Chart Labels resource</li>
<li>Setting Chart value resource</li>
<li>Set the value visible in the chart</li>
<li>Apply Styles</li>
<li>Apply Borders</li>
<li>Give Number format if necessary</li>
<li>Save the file</li>
<li>At last Launch the file</li>
<p>Wow!. That&#8217;s cool right?</p>
<p>Not yet finished!. There are so many things you can try with your sheet object. I suggest you to try those. You will get surprised.</p>
<div id="attachment_10031" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956.png"><img decoding="async" aria-describedby="caption-attachment-10031" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956.png" alt="Working With Charts Using Spire XLS Sheet Object" width="650" height="233" class="size-full wp-image-10031" srcset="/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956.png 650w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956-300x108.png 300w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956-400x143.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10031" class="wp-caption-text">Working With Charts Using Spire XLS Sheet Object</p></div>
<div id="attachment_10041" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977.png"><img decoding="async" aria-describedby="caption-attachment-10041" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977.png" alt="Working With Charts Using Spire XLS Sheet Object" width="650" height="270" class="size-full wp-image-10041" srcset="/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977.png 650w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977-300x125.png 300w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977-400x166.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10041" class="wp-caption-text">Working With Charts Using Spire XLS Sheet Object</p></div>
<p>If you want you can set different chart types too, it will give you a great design in your chart. The most useful chart types which I uses is Bar3DClustered, 3DBubble, Bubble, Column3D and many more.</p>
<div id="attachment_10051" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object.png"><img decoding="async" aria-describedby="caption-attachment-10051" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189.png" alt="Working_With_Charts_Using_Spire_XLS_Chart_Object" width="650" height="195" class="size-full wp-image-10051" srcset="/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189.png 650w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189-300x90.png 300w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189-400x120.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10051" class="wp-caption-text">Working_With_Charts_Using_Spire_XLS_Chart_Object</p></div>
<p>This product gives you many ways to make your chart in the way you like. There are plenty of options available to so so like you can set the Legend Position by using LegendPositionType property.</p>
<p>Next we will see how we can implement Column chart, what ever we have discusses will be same for every charts, but it may have some different properties which is strictly depends on the chart type. </p>
<p><strong>Column Chart</strong></p>
<p>Now we will create an another button and name it Column Chart. And in the button click you need to add the following codes.</p>
<p><strong>C# Code</strong></p>
<p>[csharp]<br />
private void button2_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                //Load Workbook<br />
                Workbook workbook = new Workbook();<br />
                workbook.LoadFromFile(@&quot;D:\Sample.xlsx&quot;);<br />
                Worksheet sheet = workbook.Worksheets[0];<br />
                //Add Chart and Set Chart Data Range<br />
                Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);<br />
                chart.DataRange = sheet.Range[&quot;D1:E17&quot;];<br />
                chart.SeriesDataFromRange = false;<br />
                //Chart Position<br />
                chart.LeftColumn = 1;<br />
                chart.TopRow = 19;<br />
                chart.RightColumn = 8;<br />
                chart.BottomRow = 33;<br />
                //Chart Border<br />
                chart.ChartArea.Border.Weight = ChartLineWeightType.Medium;<br />
                chart.ChartArea.Border.Color = Color.SandyBrown;<br />
                //Chart Title<br />
                chart.ChartTitle = &quot;Parts Sales Info&quot;;<br />
                chart.ChartTitleArea.Font.FontName = &quot;Calibri&quot;;<br />
                chart.ChartTitleArea.Font.Size = 13;<br />
                chart.ChartTitleArea.Font.IsBold = true;<br />
                //Chart Axes<br />
                chart.PrimaryCategoryAxis.Title = &quot;Parts&quot;;<br />
                chart.PrimaryCategoryAxis.Font.Color = Color.Blue;<br />
                chart.PrimaryValueAxis.Title = &quot;Amounts&quot;;<br />
                chart.PrimaryValueAxis.HasMajorGridLines = false;<br />
                chart.PrimaryValueAxis.MaxValue = 350;<br />
                chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;<br />
                //Chart Legend<br />
                chart.Legend.Position = LegendPositionType.Right;<br />
                //Save and Launch<br />
                workbook.SaveToFile(&quot;ExcelColumnChart.xlsx&quot;, ExcelVersion.Version2010);<br />
                System.Diagnostics.Process.Start(&quot;ExcelColumnChart.xlsx&quot;);</p>
<p>            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p><strong>VB.NET Code</strong></p>
<p>[vb]<br />
 &#8216;Load Workbook<br />
            Dim workbook As New Workbook()<br />
            workbook.LoadFromFile(&quot;E:\Sample.xlsx&quot;)<br />
            Dim sheet As Worksheet = workbook.Worksheets(0)<br />
            &#8216;Add Chart and Set Chart Data Range<br />
            Dim chart As Chart = sheet.Charts.Add(ExcelChartType.ColumnClustered)<br />
            chart.DataRange = sheet.Range(&quot;D1:E17&quot;)<br />
            chart.SeriesDataFromRange = False<br />
            &#8216;Chart Position<br />
            chart.LeftColumn = 1<br />
            chart.TopRow = 19<br />
            chart.RightColumn = 8<br />
            chart.BottomRow = 33<br />
            &#8216;Chart Border<br />
            chart.ChartArea.Border.Weight = ChartLineWeightType.Medium<br />
            chart.ChartArea.Border.Color = Color.SandyBrown<br />
            &#8216;Chart Title<br />
            chart.ChartTitle = &quot;Parts Sales Info&quot;<br />
            chart.ChartTitleArea.Font.FontName = &quot;Calibri&quot;<br />
            chart.ChartTitleArea.Font.Size = 13<br />
            chart.ChartTitleArea.Font.IsBold = True<br />
            &#8216;Chart Axes<br />
            chart.PrimaryCategoryAxis.Title = &quot;Parts&quot;<br />
            chart.PrimaryCategoryAxis.Font.Color = Color.Blue<br />
            chart.PrimaryValueAxis.Title = &quot;Amounts&quot;<br />
            chart.PrimaryValueAxis.HasMajorGridLines = False<br />
            chart.PrimaryValueAxis.MaxValue = 350<br />
            chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90<br />
            &#8216;Chart Legend<br />
            chart.Legend.Position = LegendPositionType.Right<br />
            &#8216;Save and Launch<br />
            workbook.SaveToFile(&quot;ExcelColumnChart.xlsx&quot;, ExcelVersion.Version2010)<br />
            System.Diagnostics.Process.Start(&quot;ExcelColumnChart.xlsx&quot;)</p>
<p>[/vb]</p>
<p>Now if you run the code, you can see an output as follows.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/columnchart-e1439304127270.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/columnchart-e1439304127270.png" alt="columnchart" width="650" height="398" class="alignnone size-full wp-image-9061" srcset="/wp-content/uploads/2015/08/columnchart-e1439304127270.png 650w, /wp-content/uploads/2015/08/columnchart-e1439304127270-300x184.png 300w, /wp-content/uploads/2015/08/columnchart-e1439304127270-400x245.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p><strong>Excel Bar Chart</strong></p>
<p>Before going through you must add an new namespace as follows.</p>
<p>[csharp]<br />
using Spire.Xls.Charts;<br />
[/csharp]<br />
Now we will create an another button in our form and in the click event we will write the receding lines of codes.</p>
<p>[csharp]<br />
  private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                Workbook workbook = new Workbook();<br />
                //Initailize worksheet<br />
                workbook.CreateEmptySheets(1);<br />
                Worksheet sheet = workbook.Worksheets[0];<br />
                sheet.Name = &quot;Chart data&quot;;<br />
                sheet.GridLinesVisible = false;<br />
                //Writes chart data<br />
                CreateChartData(sheet);<br />
                //Add a new  chart worsheet to workbook<br />
                Chart chart = sheet.Charts.Add();<br />
                //Set region of chart data<br />
                chart.DataRange = sheet.Range[&quot;A1:C5&quot;];<br />
                chart.SeriesDataFromRange = false;<br />
                //Set position of chart<br />
                chart.LeftColumn = 1;<br />
                chart.TopRow = 6;<br />
                chart.RightColumn = 11;<br />
                chart.BottomRow = 29;<br />
                chart.ChartType = ExcelChartType.Bar3DClustered;<br />
                //Chart title<br />
                chart.ChartTitle = &quot;Sales market by country&quot;;<br />
                chart.ChartTitleArea.IsBold = true;<br />
                chart.ChartTitleArea.Size = 12;<br />
                chart.PrimaryCategoryAxis.Title = &quot;Country&quot;;<br />
                chart.PrimaryCategoryAxis.Font.IsBold = true;<br />
                chart.PrimaryCategoryAxis.TitleArea.IsBold = true;<br />
                chart.PrimaryCategoryAxis.TitleArea.TextRotationAngle = 90;<br />
                chart.PrimaryValueAxis.Title = &quot;Sales(in Dollars)&quot;;<br />
                chart.PrimaryValueAxis.HasMajorGridLines = false;<br />
                chart.PrimaryValueAxis.MinValue = 1000;<br />
                chart.PrimaryValueAxis.TitleArea.IsBold = true;<br />
                foreach (ChartSerie cs in chart.Series)<br />
                {<br />
                    cs.Format.Options.IsVaryColor = true;<br />
                    cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;<br />
                }<br />
                chart.Legend.Position = LegendPositionType.Top;<br />
                workbook.SaveToFile(&quot;Sample.xls&quot;);<br />
                ExcelDocViewer(workbook.FileName);</p>
<p>            }<br />
            catch (Exception)<br />
            {<br />
                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p>As you can see we are calling a function <em>CreateChartData</em> to generate the data, so now we will write the function body.</p>
<p>[csharp]<br />
private void CreateChartData(Worksheet sheet)<br />
        {<br />
            //Country<br />
            sheet.Range[&quot;A1&quot;].Value = &quot;Country&quot;;<br />
            sheet.Range[&quot;A2&quot;].Value = &quot;Cuba&quot;;<br />
            sheet.Range[&quot;A3&quot;].Value = &quot;Mexico&quot;;<br />
            sheet.Range[&quot;A4&quot;].Value = &quot;France&quot;;<br />
            sheet.Range[&quot;A5&quot;].Value = &quot;German&quot;;<br />
            //Jun<br />
            sheet.Range[&quot;B1&quot;].Value = &quot;Jun&quot;;<br />
            sheet.Range[&quot;B2&quot;].NumberValue = 6000;<br />
            sheet.Range[&quot;B3&quot;].NumberValue = 8000;<br />
            sheet.Range[&quot;B4&quot;].NumberValue = 9000;<br />
            sheet.Range[&quot;B5&quot;].NumberValue = 8500;<br />
            //Jun<br />
            sheet.Range[&quot;C1&quot;].Value = &quot;Aug&quot;;<br />
            sheet.Range[&quot;C2&quot;].NumberValue = 3000;<br />
            sheet.Range[&quot;C3&quot;].NumberValue = 2000;<br />
            sheet.Range[&quot;C4&quot;].NumberValue = 2300;<br />
            sheet.Range[&quot;C5&quot;].NumberValue = 4200;<br />
            //Style<br />
            sheet.Range[&quot;A1:C1&quot;].Style.Font.IsBold = true;<br />
            sheet.Range[&quot;A2:C2&quot;].Style.KnownColor = ExcelColors.LightYellow;<br />
            sheet.Range[&quot;A3:C3&quot;].Style.KnownColor = ExcelColors.LightGreen1;<br />
            sheet.Range[&quot;A4:C4&quot;].Style.KnownColor = ExcelColors.LightOrange;<br />
            sheet.Range[&quot;A5:C5&quot;].Style.KnownColor = ExcelColors.LightTurquoise;<br />
            //Border<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;B2:C5&quot;].Style.NumberFormat = &quot;\&quot;$\&quot;#,##0&quot;;<br />
        }<br />
[/csharp]</p>
<p>And we will use the preceding function for viewing our chart created.</p>
<p>[csharp]<br />
private void ExcelDocViewer(string fileName)<br />
        {<br />
            try<br />
            {<br />
                System.Diagnostics.Process.Start(fileName);<br />
            }<br />
            catch { }<br />
        }<br />
[/csharp]</p>
<p>Now it is time to run our program. You will see the output as follows.</p>
<div id="attachment_9071" style="width: 310px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart.png"><img decoding="async" aria-describedby="caption-attachment-9071" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart.png" alt="Excel Bar Chart" width="300" height="300" class="size-full wp-image-9071" srcset="/wp-content/uploads/2015/08/Excel_Bar_Chart.png 300w, /wp-content/uploads/2015/08/Excel_Bar_Chart-150x150.png 150w, /wp-content/uploads/2015/08/Excel_Bar_Chart-130x130.png 130w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-9071" class="wp-caption-text">Excel Bar Chart</p></div>
<div id="attachment_9081" style="width: 669px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart_Output.png"><img decoding="async" aria-describedby="caption-attachment-9081" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart_Output.png" alt="Excel Bar Chart " width="659" height="458" class="size-full wp-image-9081" srcset="/wp-content/uploads/2015/08/Excel_Bar_Chart_Output.png 659w, /wp-content/uploads/2015/08/Excel_Bar_Chart_Output-300x208.png 300w, /wp-content/uploads/2015/08/Excel_Bar_Chart_Output-160x110.png 160w, /wp-content/uploads/2015/08/Excel_Bar_Chart_Output-400x278.png 400w" sizes="(max-width: 659px) 100vw, 659px" /></a><p id="caption-attachment-9081" class="wp-caption-text">Excel Bar Chart</p></div>
<p>As you can see it is very easy to give styles and border to our chart.</p>
<p>[csharp]<br />
//Style<br />
            sheet.Range[&quot;A1:C1&quot;].Style.Font.IsBold = true;<br />
            sheet.Range[&quot;A2:C2&quot;].Style.KnownColor = ExcelColors.LightYellow;<br />
            sheet.Range[&quot;A3:C3&quot;].Style.KnownColor = ExcelColors.LightGreen1;<br />
            sheet.Range[&quot;A4:C4&quot;].Style.KnownColor = ExcelColors.LightOrange;<br />
            sheet.Range[&quot;A5:C5&quot;].Style.KnownColor = ExcelColors.LightTurquoise;<br />
            //Border<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;B2:C5&quot;].Style.NumberFormat = &quot;\&quot;$\&quot;#,##0&quot;;<br />
[/csharp]</p>
<p>Like this we can crate Line Chart, Radar Chart and many more. Please try those too. Now we will see How to Save Excel Charts as Images.</p>
<p><strong>How to Save Excel Charts as Images</strong></p>
<p>Create another button and write the preceding codes in button click.</p>
<p>[csharp]<br />
private void button2_Click(object sender, EventArgs e)<br />
        {<br />
            Workbook workbook = new Workbook();<br />
            workbook.LoadFromFile(&quot;D:\\Sample.xlsx&quot;, ExcelVersion.Version2010);<br />
            Worksheet sheet = workbook.Worksheets[0];<br />
            Image[] imgs = workbook.SaveChartAsImage(sheet);<br />
            for (int i = 0; i &lt; imgs.Length; i++)<br />
            {<br />
                imgs[i].Save(string.Format(&quot;img-{0}.png&quot;, i), System.Drawing.Imaging.ImageFormat.Png);<br />
            }</p>
<p>        }<br />
[/csharp]</p>
<p>Here we are taking a file called Sample.xlsx and loop through the charts inside the file and save those as images with few lines codes. Sounds good right?</p>
<p><strong>VB.Net Code</strong><br />
[vb]<br />
Dim workbook As New Workbook()<br />
workbook.LoadFromFile(&quot;D:\\Sample.xlsx&quot;, ExcelVersion.Version2010)<br />
Dim sheet As Worksheet = workbook.Worksheets(0)<br />
Dim imgs As Image() = workbook.SaveChartAsImage(sheet)<br />
For i As Integer = 0 To imgs.Length &#8211; 1<br />
    imgs(i).Save(String.Format(&quot;img-{0}.png&quot;, i), ImageFormat.Png)<br />
Next<br />
[/vb]</p>
<p><strong>Conclusion</strong></p>
<p>I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/working-with-charts-using-spire-xls/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
