I am using the Mailchimp template to send emails through Mandrill. Email being sent successfully. But the variables are not rendering. I tried lots of settings but unfortunately, it is not working. My code is looking like the following.
<p>Dear {{customerName}},</p>
<p>Thank you for using XXXXX to process your return.</p>
<p>All you have to do is bring your parcel along with this e-mail to {{pudoLocation}} at {{emailPudoAddress}}.</p>
And In the Email output, it is showing like this.
And My request JSON to API https://mandrillapp.com/api/1.0/messages/send-template.json is:-
valid json is `{
"key": "xxxxxxxxxxxxxxx",
"template_name": "TestTemplate",
"template_content": [],
"message": {
"subject": "TestEmail",
"from_email": "xxx.xx#xxxxx.in",
"from_name": "Drop2Shop",
"to": [{
"Email": "xxxxx.xxx#xxxxxx.in",
"Name": "Amrit Pannu",
"Type": "to"
}],
"headers": {
"Reply-To": "xxxxx.xxx#xxxx.in"
},
"important": false,
"track_clicks": true,
"track_opens": true,
"merge_language": "handlebars",
"global_merge_vars": [{
"name": "pudoLocation",
"content": "TRK00000028"
},
{
"name": "customerName",
"content": "TRK00000028"
}],
"tags": [""]
}
}`
Please can someone help me here what I missing in this?
Thanks and Advance
You can pass global variables in mandrill using *|VAR1|*. To pass array you can use {{handlebars}}.
The content will be like this:
<p>Dear *|customerName|*,</p>
<p>Thank you for using XXXXX to process your return.</p>
<p>All you have to do is bring your parcel along with this e-mail to *|pudoLocation|* at *|emailPudoAddress|*.</p>
The JSON should be like this only:
{
"key": "XXXXXXXXXXXXXXX",
"template_name": "XXXXXXXXXXXXXXXXXX",
"template_content": [],
"message": {
"subject": "TestEmail",
"from_email": "xxxx#xxxxxxxxxxx.in",
"from_name": "xxxxxx",
"to": [
{
"email": "xxxx#xxxxxxxxxxx.in",
"name": "xxxxx xxxxx",
"type": "to"
}
],
"headers": {
"reply_to": "xxxx.xxxx#xxxx.in"
},
"important": false,
"track_opens": true,
"track_clicks": true,
"merge_language": "handlebars",
"global_merge_vars": [
{
"name": "trackingNumber",
"content": "TRK00000028"
},
{
"name": "customerName",
"content": "Amrit Pannu"
},
{
"name": "eCommerceRetailer",
"content": "Jojo Retailer"
},
{
"name": "goodsDescription",
"content": "Tricycles, Scooters, and Similar Wheeled Toys; Dolls' Carriages"
},
{
"name": "shippingDate",
"content": "2021-07-07"
},
{
"name": "numberOfPackages",
"content": "45"
},
{
"name": "shipFromAddress",
"content": "IRELAND"
},
{
"name": "shipToAddress",
"content": "Britain"
},
{
"Name": "pudoAddress",
"Content": "USA"
},
{
"name": "shipFromContact",
"content": "Commin"
},
{
"name": "shipToContact",
"content": "Stark"
},
{
"name": "customerReference",
"content": "DF7889FSDHCB"
},
{
"name": "pudoLocation",
"content": "Denmark"
},
{
"name": "emailPudoAddress",
"content": "amrit#mailinator.com"
},
{
"name": "unsubscribePageUrl",
"content": ""
},
{
"name": "email",
"content": "amrit#mailinator.com"
},
{
"name": "scanEventTime",
"content": "12:07"
},
{
"name": "scanEventDate",
"content": "07 July 2021"
},
{
"name": "packageItems",
"content": [
{
"GoodsDescription": "869c6f67-f33d-4b30-a274-79b635d12461",
"ReturnReason": "c3b4b071-7664-4060-a39f-52c24147a1ce",
"Quantity": 3,
"Value": 6
},
{
"GoodsDescription": "5e2c625b-74e6-4e90-bb52-6595e9f3d088",
"ReturnReason": "f0949b28-f9a7-406e-8676-b8ce6c714509",
"Quantity": 3,
"Value": 14
},
{
"GoodsDescription": "cffe036a-2441-41af-82e1-130f9169924b",
"ReturnReason": "f31956b9-c24e-492e-b11f-4b4e19489b13",
"Quantity": 1,
"Value": 5
},
{
"GoodsDescription": "f8f64467-6926-4f08-9d4e-aa924dc1af35",
"ReturnReason": "d1f759b0-8e54-4119-94ee-6afe1bc49766",
"Quantity": 4,
"Value": 0
},
{
"GoodsDescription": "496f4e0e-739d-4fce-8a37-85113f27c4d4",
"ReturnReason": "b8d98439-928f-4e6c-bb56-01e6f8fb6be6",
"Quantity": 2,
"Value": 5
},
{
"GoodsDescription": "afe2986c-e51e-4cfe-9506-f9ef2afa5657",
"ReturnReason": "4e6e34f6-d921-46fb-8f4a-b04afd0856a7",
"Quantity": 4,
"Value": 12
},
{
"GoodsDescription": "13ac561a-d161-46a5-9795-8481e99a3afd",
"ReturnReason": "73f4441b-dcff-4f68-a58e-320a29a167c8",
"Quantity": 1,
"Value": 7
},
{
"GoodsDescription": "135e083b-0408-4445-9a0c-3656a46f7eab",
"ReturnReason": "325c7144-8f7d-4712-b708-1702416ca02c",
"Quantity": 2,
"Value": 13
},
{
"GoodsDescription": "ee510bfd-58ea-4707-9c52-26913b190b27",
"ReturnReason": "854629a5-289b-46c9-a072-099e2a572307",
"Quantity": 4,
"Value": 12
},
{
"GoodsDescription": "b6d6fa6e-a327-4014-b019-0c4cd0098da6",
"ReturnReason": "02394799-761c-46f0-af79-d8bc92b2c1b5",
"Quantity": 1,
"Value": 13
}
]
},
{
"name": "currentYear",
"content": 2021
}
],
"tags": null,
"inline_css": true
}
For more information, please see this: https://mailchimp.com/developer/transactional/docs/templates-dynamic-content/#dynamic-content
I'm probably too late, but if it can help someone else.
It's not working because you have to remove all the backslashes Mailchimp added when send it to Mandrill before your variables. Change : \{{customerName}} to {{customerName}}
I am making some mistake in returning data from c# to angular controller,Here is my C# code
public ActionResult FlightDisp()
{
dynamic parsedJson = "";
string myJsonResponse = "";
try
{
const string URL = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
string token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(URL);
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "");
Task<HttpResponseMessage> response = client.SendAsync(request);
myJsonResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(response.Result.Content.ReadAsStringAsync().Result).ToString();
JObject jsonObject = JObject.Parse(myJsonResponse);
parsedJson = JsonConvert.DeserializeObject(myJsonResponse);
}
catch (Exception ex)
{
}
return Json( parsedJson );
}
Whatever i get is parsed json is perfect but when i pass the parsedJson from c# to angular controller it becomes something like:
[
[
[
[
[
[]
],
[
[
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[
[
[]
],
[
[]
]
]
],
[
[
[
[
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
]
],
[
[
[
[]
],
[
[]
],
[
[]
]
]
],
[
[
[
[]
],
[
[]
]
]
],
[
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
]
]
],
[
[]
],
[
[
[
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[
[
[]
],
[
[]
]
]
],
[
[
[
[]
],
[
[
[
[]
],
[
[]
]
]
]
Its completely empty but parsedJson has value :
{{
"data": [
{
"type": "hotel-offers",
"hotel": {
"type": "hotel",
"hotelId": "ALNYC647",
"chainCode": "AL",
"dupeId": "501447323",
"name": "Aloft Manhattan Downtown - Financial District",
"rating": "4",
"cityCode": "NYC",
"latitude": 40.71041,
"longitude": -74.00666,
"hotelDistance": {
"distance": 0.4,
"distanceUnit": "KM"
},
"address": {
"lines": [
"49 53 ANN STREET"
],
"postalCode": "10038",
"cityName": "NEW YORK",
"countryCode": "US",
"stateCode": "NY"
},
"contact": {
"phone": "+1 212 513-0003",
"fax": "+1 212 513-0004",
"email": "info#aloftmanhattandowntown.com"
},
"description": {
"lang": "en",
"text": "Celebrate your style at Aloft Manhattan Downtown - Financial District, a hip new hotel where you'll be close to corporate headquarters, Wall Street and the World Trade Center. We offer easy-breezy access to Big Apple hotspots via nearby subway lines. Meet & mingle with friends at our w xyz(SM) bar, grab a sweet, savory or healthy snack from re:fuel by Aloft(SM), our 24/7 pantry or play in our re:mix(SM) lounge. Plus, you can always stay connected with free hotel-wide wired and wireless High Speed Internet Access! Breeze into one of our Aloft rooms, featuring our ultra-comfortable signature bed, walk-in shower, custom amenities by Bliss® Spa and more."
},
"amenities": [
"SPA",
"SERV_DOGS_ALWD",
"ACC_TOILETS",
"HANDRAIL_BTHRM",
"24_HOUR_FRONT_DESK",
"CAR_RENTAL",
"EXPRESS_CHECK_IN",
"LOUNGE",
"ICE_MACHINES",
"FLORIST",
"TRAVEL_AGENCY",
"CONCIERGE",
"SAFE_DEP_BOX",
"LAUNDRY_SVC",
"ATM/CASH_MACHINE",
"EXPRESS_CHECK_OUT",
"WEDDING_SERVICES",
"GYM",
"RESTAURANT",
"HI_INTERNET",
"FREE_INTERNET",
"WIRELESS_CONNECTIVITY",
"ELEVATOR",
"PETS_ALLOWED",
"PHOTOCOPIER",
"PRINTER",
"BUSINESS_CENTER",
"MEETING_FACILITIES",
"INTERNET-HI_SPEED_IN_RM",
"WI-FI_IN_ROOM",
"NONSMOKING_RMS",
"FREE_LOCAL_CALLS",
"TEA/COFFEE_MK_FACILITIES",
"ALARM_CLOCK",
"AIR_CONDITIONING",
"SAFE",
"IRON/IRON_BOARD",
"CRIBS_AVAILABLE",
"TELEVISION",
"HAIR_DRYER",
"VOICEMAIL_IN_ROOM",
"PHONE-DIR_DIAL",
"CORDLESS_PHONE",
"REFRIGERATOR",
"OUTLET_ADAPTERS",
"CABLE_TELEVISION",
"FITNESS_CENTER"
]
},
"available": true,
"offers": [
{
"id": "LBRB9R0B0X",
"checkInDate": "2020-09-13",
"checkOutDate": "2020-09-14",
"rateCode": "S9R",
"rateFamilyEstimated": {
"code": "SRS",
"type": "C"
},
"room": {
"type": "XMI",
"typeEstimated": {
"beds": 1,
"bedType": "QUEEN"
},
"description": {
"lang": "EN",
"text": "Marriott Senior Discount, includes 62 years and older valid ID \nSleeps 2, Fast & free WiFi throughout the hotel\n, 1 Queen, 200sqft/18sqm-220sqft/20sqm, Wireles"
}
},
"guests": {
"adults": 1
},
"price": {
"currency": "USD",
"base": "127.00",
"total": "149.25",
"variations": {
"average": {
"base": "127.00"
},
"changes": [
{
"startDate": "2020-09-13",
"endDate": "2020-09-14",
"base": "127.00"
}
]
}
},
"policies": {
"paymentType": "guarantee",
"cancellation": {
"deadline": "2020-09-13T09:29:00+05:30"
}
}
}
],
"self": "https://test.api.amadeus.com/v2/shopping/hotel-offers/by-hotel?hotelId=ALNYC647"
},
{
"type": "hotel-offers",
"hotel": {
"type": "hotel",
"hotelId": "HXNYC432",
"chainCode": "HX",
"dupeId": "700051862",
"name": "HAMPTON INN MANHATTAN-DOWNTOWN-FINANCIAL",
"rating": "2",
"cityCode": "NYC",
"latitude": 40.70312,
"longitude": -74.01228,
"hotelDistance": {
"distance": 1.3,
"distanceUnit": "KM"
},
"address": {
"lines": [
"32 PEARL ST"
],
"postalCode": "10004",
"cityName": "NEW YORK",
"countryCode": "US",
"stateCode": "NY"
},
"contact": {
"phone": "1-212-480-3500",
"fax": "1-212-480-3700"
},
"amenities": [
"BUSINESS_CENTER",
"ADAPTED_PHONES",
"WIDE_ENTRANCE",
"WIDE_CORRIDORS",
"FIRST_AID_STAF",
"INT_ROOM_ENTRY",
"EMERG_LIGHTING",
"FIRE_DETECTORS",
"EXTINGUISHERS",
"FIRE_SAFETY",
"RESTRIC_RM_ACC",
"SMOKE_DETECTOR",
"SPRINKLERS",
"LAUNDRY_SVC",
"PARKING",
"PETS_ALLOWED",
"SAFE_DEP_BOX",
"AIR_CONDITIONING",
"HAIR_DRYER",
"MOVIE_CHANNELS",
"NONSMOKING_RMS",
"PC_HOOKUP_INRM",
"TELEVISION",
"FITNESS_CENTER"
],
"media": [
{
"uri": "http://uat.multimediarepository.testing.amadeus.com/cmr/retrieve/hotel/9E95CFEC3B6F4C459EDC0F267159B799",
"category": "EXTERIOR"
}
]
},
"available": true,
"offers": [
{
"id": "Y0IT2BLO9V",
"checkInDate": "2020-09-13",
"checkOutDate": "2020-09-14",
"rateCode": "RAC",
"rateFamilyEstimated": {
"code": "AAA",
"type": "C"
},
"commission": {
"percentage": "10.00"
},
"boardType": "BREAKFAST",
"room": {
"type": "C1Q",
"typeEstimated": {
"category": "ACCESSIBLE_ROOM",
"beds": 1,
"bedType": "QUEEN"
},
"description": {
"lang": "EN",
"text": "AAA RATE\n1 QUEEN ACCESSIBLE ROLL IN SHOWER NONSMOKING\nHDTV/WORK AREA"
}
},
"guests": {
"adults": 1
},
"price": {
"currency": "USD",
"base": "594.15",
"total": "685.29",
"variations": {
"average": {
"base": "594.15"
},
"changes": [
{
"startDate": "2020-09-13",
"endDate": "2020-09-14",
"base": "594.15"
}
]
}
},
"policies": {
"paymentType": "guarantee",
"cancellation": {
"deadline": "2020-09-10T09:30:00+05:30"
}
}
}
],
"self": "https://test.api.amadeus.com/v2/shopping/hotel-offers/by-hotel?hotelId=HXNYC432"
},
{
"type": "hotel-offers",
"hotel": {
"type": "hotel",
"hotelId": "BWNYC133",
"chainCode": "BW",
"dupeId": "700101379",
"name": "Best Western Bowery Hanbee Hotel",
"rating": "2",
"cityCode": "NYC",
"latitude": 40.7184,
"longitude": -73.99518,
"hotelDistance": {
"distance": 1.0,
"distanceUnit": "KM"
},
"address": {
"lines": [
"231 GRAND STREET"
],
"postalCode": "10013",
"cityName": "NEW YORK CITY",
"countryCode": "US",
"stateCode": "NY"
},
"contact": {
"phone": "+1 212 9251177",
"fax": "+1 212 9255533",
"email": "33133#hotel.bestwestern.com"
},
"description": {
"lang": "en",
"text": "Stay at this 100% non-smoking New York City, New York hotel located next to the subway and key local attractions such as Canal Street, Chinatown and Little Italy. Welcome to the Best Western Bowery Hanbee Hotel, where guests will find exceptional customer service and accommodations at an affordable rate. This New York City hotel features well-appointed guest rooms and suites, each offering cable satellite television with free HBO® and free wireless high-speed Internet access. Guests staying at this 100% non-smoking hotel will enjoy a complimentary hot breakfast buffet each morning before heading out to sightsee. Additional amenities include an exercise facility and a full-service business center. The Best Western Bowery Hanbee Hotel is ideally located less than one mile from many New York attractions including Chinatown, Little Italy, the Wall Street financial district and the World Trade Center Memorial. Hotel guests will enjoy an afternoon of shopping on 5th Avenue or visiting key sights such as Ellis Island, the Statue of Liberty, the Empire State Building and Times Square. Corporate travelers will appreciate being a half mile from the New York Stock Exchange, the Federal Reserve Bank, JP Morgan and American Express®. This New York hotel is also ideal for viewing several annual events including the Macy's Thanksgiving Day Parade®, the Chinese New Year and the Tribeca Film Festival. The friendly, helpful staff at the Best Western Bowery Hanbee Hotel is ready to ensure a fun-filled memorable stay in New York, New York. Make a reservation today and save! Enjoy your stay!"
},
"amenities": [
"24_HOUR_FRONT_DESK",
"GYM",
"HI_INTERNET",
"ELEVATOR",
"ICE_MACHINES",
"SPRINKLERS",
"FIRE_DETECTORS",
"FEMA_FIRE_SAFETY_COMPLIANT",
"SMOKE_DETECTOR",
"EMERG_LIGHTING",
"HANDICAP_FAC",
"BUSINESS_CENTER",
"FREE_LOCAL_CALLS",
"PHONE-DIR_DIAL",
"INTERNET-HI_SPEED_IN_RM",
"HAIR_DRYER",
"AIR_CONDITIONING",
"CABLE_TELEVISION",
"VOICEMAIL_IN_ROOM",
"SAFE",
"WAKEUP_SERVICE",
"ALARM_CLOCK",
"TEA/COFFEE_MK_FACILITIES",
"CRIBS_AVAILABLE"
],
"media": [
{
"uri": "http://uat.multimediarepository.testing.amadeus.com/cmr/retrieve/hotel/A15115741A8747538ECDBB2AA76B7DE9",
"category": "EXTERIOR"
}
]
},
"available": true,
"offers": [
{
"id": "MLX8YR77R7",
"checkInDate": "2020-09-13",
"checkOutDate": "2020-09-14",
"rateCode": "SRS",
"rateFamilyEstimated": {
"code": "SRS",
"type": "C"
},
"commission": {
"percentage": "10"
},
"boardType": "BREAKFAST",
"room": {
"type": "A1Q",
"typeEstimated": {
"category": "ACCESSIBLE_ROOM",
"beds": 1,
"bedType": "QUEEN"
},
"description": {
"lang": "EN",
"text": "SENIOR RATE*CITIZENS 55YRS PLUS OR AARP ID\n1 QUEEN BED,MOBILITY ACC,COMMASSIST,ROLL SHWR,\nNSMK,CONTINENTAL BREAKFAST"
}
},
"guests": {
"adults": 1
},
"price": {
"currency": "USD",
"base": "242.10",
"total": "281.31",
"variations": {
"average": {
"base": "242.10"
},
"changes": [
{
"startDate": "2020-09-13",
"endDate": "2020-09-14",
"base": "242.10"
}
]
}
},
"policies": {
"paymentType": "guarantee",
"cancellation": {
"deadline": "2020-09-11T09:30:00+05:30"
}
}
}
],
"self": "https://test.api.amadeus.com/v2/shopping/hotel-offers/by-hotel?hotelId=BWNYC133"
}
],
"meta": {
"links": {
"next": "https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=NYC&page[offset]=BF2MJFOB9ASN_100"
}
}
}}
When i pass the above value to the angular controller its becomes empty ,My Angular code
.then(function successCallback(response) {
var hexa = response.data;
alert(hexa);
console.log(hexa);
}
I am facing an issue while writing query to make a group by on inner list data to filter the outer list.
I have a collection structure like
"products"
{
"id": "97",
"name": "YI1",
"projects": [
{
"id": "92",
"name": "MUM",
"branches": [
{
"id": "62",
"name": "ON Service",
"geographyid": "84",
"geographyname": "North America",
"countryid": "52",
"countryname": "Canada"
}
],
"customers": [
{
"id": "80",
"name": "HEALTH SCIENCES"
}
]
}
],
},
"products"
{
"id": "96",
"name": "YI2",
"projects": [
{
"id": "94",
"name": "HHS",
"branches": [
{
"id": "64",
"name": "Hamilton ON Service",
"geographyid": "44",
"geographyname": "Asia",
"countryid": "58",
"countryname": "China"
}
],
"customers": [
{
"id": "40",
"name": "SCIENCES"
}
]
}
],
]
}
I am trying to have a new collection which can return an output as below
"Geography"{
"geographyid": "44",
"geographyname": "Asia",
"Country"
{
"countryid": "58",
"countryname": "China",
"branches"
{
"id": "94",
"name": "HHS
"customers"
{
"id": "40",
"name": "SCIENCES"
"projects"
{
"id": "94",
"name": "HHS",
"products"
{
"id": "96",
"name": "YI2",
}
}
},
}
}
},
"Geography"{
"geographyid": "84",
"geographyname": "North America"
"Country"
{
"countryid": "52",
"countryname": "Canada"
"branches"
{
"id": "62",
"name": "ON Service",
"customers"
{
"id": "80",
"name": "HEALTH SCIENCES"
"projects"
{
"id": "92",
"name": "MUM",
"products"
{
"id": "97",
"name": "YI1",
}
}
},
}
}
}
I tried multiple options and also write below query but I am still not getting required result.
var treeGroup = siteList.SelectMany(a => a.projects.Select(b => new { A = a, B = b }).ToList()).ToList()
.GroupBy(ol => new { ol.B.geographyid, ol.B.geographyname })
.Select(gGroup => new TreeNodes
{
id = gGroup.Key.geographyid,
name = gGroup.Key.geographyname,
type = Costants.geographyTreeNode,
parentid = string.Empty,
children = gGroup
.GroupBy(ol => new { ol.B.countryid, ol.B.countryname })
.Select(cGroup => new TreeNodes
{
id = cGroup.Key.countryid,
name = cGroup.Key.countryname,
type = Costants.countryTreeNode,
parentid = gGroup.Key.geographyid,
children = cGroup
.GroupBy(ol => new { ol.B.id, ol.B.name })
.Select(sGroup => new TreeNodes
{
id = sGroup.Key.id,
name = sGroup.Key.name,
type = Costants.branchTreeNode,
parentid = cGroup.Key.countryid,
children = sGroup
.Select(ol => new TreeNodes { id = ol.A.id, name = ol.A.name, type = Costants.siteTreeNode, parentid = sGroup.Key.id, children = new List<TreeNodes>() })
.ToList()
})
.ToList()
})
.ToList()
})
.ToList();
I can use looping logic to get the result, but I want to avoid it and try something with linq or lmbda expression.
I am able to resolve the issue. I took an additional parameters for Customers and then used the same with selectmany function on branches
I'm building a dashboard using ASP.Net MVC, Angular.js, SQL Server and Fusion charts. All my data for charting is stored in database and I'm getting them via stored procedure. Now I need to pass the results from stored procedure to Json/XML, only formats Fusion Charts supports. What would be the best method to convert this data:
Hour Input Output InTarget OutTarget
7 22314 18537 6500 4875
8 36395 29931 6500 4875
9 32661 28518 6500 4875
10 34895 29793 6500 4875
11 30300 26538 6500 4875
12 31011 26898 6500 4875
13 16363 13716 6500 4875
into this Json?
{
"chart": {
"caption": "Input and Output",
"numberprefix": "$",
"plotgradientcolor": "",
"bgcolor": "FFFFFF",
"showalternatehgridcolor": "0",
"divlinecolor": "CCCCCC",
"showvalues": "0",
"showcanvasborder": "0",
"canvasborderalpha": "0",
"canvasbordercolor": "CCCCCC",
"canvasborderthickness": "1",
"yaxismaxvalue": "30000",
"captionpadding": "30",
"yaxisvaluespadding": "15",
"legendshadow": "0",
"legendborderalpha": "0",
"palettecolors": "#f8bd19,#008ee4,#33bdda,#e44a00,#6baa01,#583e78",
"showplotborder": "0",
"showborder": "0"
},
"categories": [
{
"category": [
{
"label": "7"
},
{
"label": "8"
},
{
"label": "9"
},
{
"label": "10"
},
{
"label": "11"
},
{
"label": "12"
},
{
"label": "13"
}
]
}
],
"dataset": [
{
"seriesname": "Input",
"data": [
{
"value": "22314"
},
{
"value": "36395"
},
{
"value": "32661"
},
{
"value": "34895"
},
{
"value": "30300"
},
{
"value": "31011"
},
{
"value": "16363"
}
]
},
{
"seriesname": "Output",
"data": [
{
"value": "18537"
},
{
"value": "29931"
},
{
"value": "28518"
},
{
"value": "29793"
},
{
"value": "26538"
},
{
"value": "26898"
},
{
"value": "13716"
}
]
},
{
"seriesname": "InTarget",
"renderas": "Line",
"data": [
{
"value": "6500"
},
{
"value": "6500"
},
{
"value": "6500"
},
{
"value": "6500"
},
{
"value": "6500"
},
{
"value": "6500"
},
{
"value": "6500"
}
]
},
{
"seriesname": "OutTarget",
"renderas": "Line",
"data": [
{
"value": "4875"
},
{
"value": "4875"
},
{
"value": "4875"
},
{
"value": "4875"
},
{
"value": "4875"
},
{
"value": "4875"
},
{
"value": "4875"
}
]
}
]
}
What I'm thinking to do is:
stored procedure into datatable
put each column into separate array
convert array to Json in the format below
Is this going to be the best (performance) approach?
EDIT:
public Series[] GetGraphData(string sp)
{
var connection = ConfigurationManager.ConnectionStrings["EFDbContext"].ConnectionString;
using (var da = new SqlDataAdapter("exec " + sp, connection))
{
var dt = new DataTable();
da.Fill(dt);
da.FillSchema(dt, SchemaType.Mapped);
Series[] arrSeries = new Series[dt.Columns.Count];
foreach(DataColumn dc in dt.Columns)
{
if (dc.Ordinal == 0)
{
//Category here
}
else
{
var strarr = dt.Rows.Cast<DataRow>().Select(row => row[dc.Ordinal]).ToList();
Series s = new Series()
{
seriesname = dc.ColumnName,
renderas = "Line",
data = strarr.Select(o => new SeriesValue { value = o.ToString() }).ToList()
};
arrSeries[dc.Ordinal] = s;
}
}
return arrSeries;
}
}
I would load all the data into a datatable as you said, then have a Series object:
class Series{
public string seriesname{get;set;}
public string renderas{get;set;}
public IList<SeriesValue> data{get;set;}
}
class SeriesValue{
public string value{get;set;}
}
and return an array of Series to the frontend, serialized as JSON. Then you have the dataset array already built and you don't need to do any other processing on it.
I expect the performance bottleneck to be in loading the data from the db and sending it to the client .. the actual conversion to json shouldn't matter in the grand scheme of things.