Hi firasataries,
Refer below sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
type: "POST",
url: "VB.aspx/GetChartData",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var data1 = google.visualization.arrayToDataTable(r.d[0]);
var data2 = google.visualization.arrayToDataTable(r.d[1]);
var data3 = google.visualization.arrayToDataTable(r.d[2]);
var data4 = google.visualization.arrayToDataTable(r.d[3]);
var chart1 = new google.visualization.ComboChart($("#chart")[0]);
chart1.draw(data1, {
seriesType: 'bars', series: { 1: { type: 'line' } },
legend: { position: "none" },
bar: { groupWidth: "30%" },
isStacked: true,
title: 'Feasibility Study',
colors: ['rgb(104, 33, 33)'],
is3D: 'true', legend: 'none',
hAxis: {
title: 'Completion Year', format: '0'
},
vAxis: {
title: 'Average No. Of Days Taken to Complete Feasibility Study',
titleTextStyle: { color: 'rgb(104, 33, 33)' }, format: '0'
}
});
var chart2 = new google.visualization.ColumnChart($("#chart1")[0]);
chart2.draw(data2, {
seriesType: 'bars', series: { 1: { type: 'line' } },
legend: { position: "none" },
bar: { groupWidth: "30%" },
isStacked: true,
title: 'Budget Estimate',
colors: ['rgb(245, 121, 30)'],
is3D: 'true',
legend: 'none',
hAxis: {
title: 'Completion Year', format: '0'
},
vAxis: {
title: 'Average No. Of Days Taken to Complete Budget Estimate', format: '0'
}
});
var chart3 = new google.visualization.ColumnChart($("#chart2")[0]);
chart3.draw(data3, {
seriesType: 'bars', series: { 1: { type: 'line' } },
legend: { position: "none" },
bar: { groupWidth: "30%" },
isStacked: true,
title: 'Change Order (EHV)',
colors: ['rgb(133, 144, 175)'],
is3D: 'true',
legend: 'none',
hAxis: {
title: 'Completion Year', format: '0'
},
vAxis: {
title: 'Average No. Of Days Taken to Complete Change Order (EHV)', format: '0'
}
});
var chart4 = new google.visualization.ColumnChart($("#chart3")[0]);
chart4.draw(data4, {
seriesType: 'bars', series: { 1: { type: 'line' } },
legend: { position: "none" },
bar: { groupWidth: "30%" },
isStacked: true,
title: 'Change Order',
colors: ['#1B4589'],
is3D: 'true',
legend: 'none',
hAxis: {
title: 'Completion Year', format: '0'
},
vAxis: {
title: 'Average No. Of Days Taken to Complete Change Order', format: '0'
}
});
},
failure: function (r) {
alert(r.responseText);
},
error: function (r) {
alert(r.responseText);
}
});
}
</script>
<div id="chart" style="width: 900px; height: 500px;"></div>
<div id="chart1" style="width: 900px; height: 500px;"></div>
<div id="chart2" style="width: 900px; height: 500px;"></div>
<div id="chart3" style="width: 900px; height: 500px;"></div>
Namespaces
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web.Services
Code
<WebMethod()>
Public Shared Function GetChartData() As List(Of List(Of Object))
Dim chartDatas As List(Of List(Of Object)) = New List(Of List(Of Object))()
Dim query As String = "SELECT cast(YEAR(OrderDate) as varchar(4)) AS Year ,AVG(OrderId) AS No_of_Days FROM [Orders] GROUP BY YEAR(OrderDate), ShipCountry HAVING ShipCountry='France' ORDER BY Year DESC"
chartDatas.Add(GetData(query))
query = "SELECT cast(YEAR(OrderDate) as varchar(4)) AS Year ,AVG(OrderId) AS No_of_Days FROM [Orders] GROUP BY YEAR(OrderDate), ShipCountry HAVING ShipCountry='Germany' ORDER BY Year DESC"
chartDatas.Add(GetData(query))
query = "SELECT cast(YEAR(OrderDate) as varchar(4)) AS Year ,AVG(OrderId) AS No_of_Days FROM [Orders] GROUP BY YEAR(OrderDate), ShipCountry HAVING ShipCountry='Brazil' ORDER BY Year DESC"
chartDatas.Add(GetData(query))
query = "SELECT cast(YEAR(OrderDate) as varchar(4)) AS Year ,AVG(OrderId) AS No_of_Days FROM [Orders] GROUP BY YEAR(OrderDate), ShipCountry HAVING ShipCountry='Belgium' ORDER BY Year DESC"
chartDatas.Add(GetData(query))
Return chartDatas
End Function
Private Shared Function GetData(ByVal query As String) As List(Of Object)
Dim chartData As List(Of Object) = New List(Of Object)()
chartData.Add(New Object() {"Year", "No of Days", "KPI"})
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(query, con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myD As New DataTable
sda.Fill(myD)
If myD.Rows.Count > 0 Then
For i As Integer = 0 To myD.Rows.Count - 1
chartData.Add(New Object() {myD.Rows(i)(0), myD.Rows(i)(1), 5000})
Next
End If
Return chartData
End Using
End Using
End Using
End Function
Screenshot