var pivot_dataset = [
{ Amount: 100, Country: "Canada", Date: "FY 2005", Product: "Bike", Quantity: 2, State: "Alberta" },
{ Amount: 200, Country: "Canada", Date: "FY 2006", Product: "Van", Quantity: 3, State: "British Columbia" },
{ Amount: 300, Country: "Canada", Date: "FY 2007", Product: "Car", Quantity: 4, State: "Brunswick" },
{ Amount: 150, Country: "Canada", Date: "FY 2008", Product: "Bike", Quantity: 3, State: "Manitoba" },
{ Amount: 200, Country: "Canada", Date: "FY 2006", Product: "Car", Quantity: 4, State: "Ontario" },
{ Amount: 100, Country: "Canada", Date: "FY 2007", Product: "Van", Quantity: 1, State: "Quebec" },
{ Amount: 200, Country: "France", Date: "FY 2005", Product: "Bike", Quantity: 2, State: "Charente-Maritime" },
{ Amount: 250, Country: "France", Date: "FY 2006", Product: "Van", Quantity: 4, State: "Essonne" },
{ Amount: 300, Country: "France", Date: "FY 2007", Product: "Car", Quantity: 3, State: "Garonne (Haute)" },
{ Amount: 150, Country: "France", Date: "FY 2008", Product: "Van", Quantity: 2, State: "Gers" },
{ Amount: 200, Country: "Germany", Date: "FY 2006", Product: "Van", Quantity: 3, State: "Bayern" }
];
I want to use the data from the database.
There is no problem in my sample, but you will find below the mdf database file.
Regards,
Anis
PivotClientFeatures.cshtml:
<script>
var pivot_dataset = [];
function onLoad(args) {
$.ajax({
type: "POST",
url: "../api/OlapClient/GetData",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (val) {
pivot_dataset = JSON.parse(val);
args.model.dataSource.data = pivot_dataset;
},
});
}
//code here
</script>
OlapClientController.cs(C#):
[System.Web.Http.ActionName("GetData")]
[System.Web.Http.HttpPost]
public string GetData()
{
string sJSON = "";
//You can frame your logic here to get data from SQL database and send to client side as string format.
return sJSON;
}
|
function onLoad(args) {
$.ajax({
type: "POST",
url: "../api/OlapClient/GetData",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
success: function (val) {
pivot_dataset = JSON.parse(val);
args.model.dataSource.data = pivot_dataset;
},
});
} |
CREATE TABLE [dbo].[PivotClient] (
[Id] INT NOT NULL,
[DateCtrl] DATETIME NOT NULL,
[Ctrl] NCHAR (50) NOT NULL,
[m] NCHAR (50) NOT NULL,
[Customer] NCHAR (50) NOT NULL,
[Quantity] INT NOT NULL,
[ErrorDescription] NCHAR (50) NOT NULL,
[Section] NCHAR (50) NOT NULL,
[nb1] INT NOT NULL,
[nb2] INT NOT NULL,
[nb3] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
function onLoad(args) {
$.ajax({
type: "POST",
url: "../api/OlapClient/GetData",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
success: function (val) {
pivot_dataset = JSON.parse(val); // get the returned JSONData from service
args.model.dataSource.data = pivot_dataset;
},
});
} |
CREATE TABLE [dbo].[PivotClient] (
[Id] INT NOT NULL,
[DateCtrl] DATETIME NOT NULL,
[Ctrl] NCHAR (50) NOT NULL,
[m] NCHAR (50) NOT NULL,
[Customer] NCHAR (50) NOT NULL,
[Quantity] INT NOT NULL,
[ErrorDescription] NCHAR (50) NOT NULL,
[Section] NCHAR (50) NOT NULL,
[nb1] INT NOT NULL,
[nb2] INT NOT NULL,
[nb3] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Add soma data and extract them to PivotClient.
Regards,
Anis.