I'm using Highcharts under C# .NET
I want to include more data to include and show them on Series.
All classes of Series (ColumnSeriesData, PieSeriesData... limit us to a number of a specific fields bellow:
public string ClassName { get; set; }
public string Color { get; set; }
public double? ColorIndex { get; set; }
public Hashtable CustomFields { get; set; }
public PieSeriesDataLabels DataLabels { get; set; }
public string Description { get; set; }
public PieSeriesDataDragDrop DragDrop { get; set; }
public string Drilldown { get; set; }
public PieSeriesDataEvents Events { get; set; }
public string Id { get; set; }
public double? Labelrank { get; set; }
public double? LegendIndex { get; set; }
public string Name { get; set; }
public bool? Selected { get; set; }
public bool? Sliced { get; set; }
public double? Y { get; set; }
How can i add a personalised field ?
Yes, each class in Highcharts.NET or Highstock.NET contains the CustomFields property where you can define fields that will later be thrown in JS. It should be added in pairs: property name and value.
API example: https://dotnet.highcharts.com/Help/Highcharts/html/class_highsoft_1_1_web_1_1_mvc_1_1_charts_1_1_spline_series.html#a911f05a5827c3d33cc5dceb79bb55b24
i'm trying to run through some JSON seralisation into some objects. pretty straight forward stuff.
for some reason i have the first part working as expected, it seralises perfectly.
the moment i wrap this JSON in an additional element the Deseralize Object passes, but the object is empty... i cannot spot the issue and i cannot seem to debug what's going on here.
string UIElement = "{\"Name\":\"X1144\",\"Order\":1,\"Tvalue\":\"int\",\"BindValue\":null,\"Default\":null,\"Disabled\":false,\"Mandatory\":true,\"MandatoryMessage\":\"this is a mandatory field\",\"Label\":\"<B> THIS is a HTML</b> label\",\"ToolTip\":\"just a tooltip\",\"PolicyProcess\":[{\"URL\":\"https://google.com\"}],\"Type\":\"RadzenColorPicker\",\"TypeOptions\":[{\"Name\":\"showHSV\",\"Value\":\"True\"},{\"Name\":\"showRGBA\",\"Value\":\"True\"},{\"Name\":\"ShowColors\",\"Value\":\"True\"},{\"Name\":\"showButton\",\"Value\":\"True\"}],\"ItemsType\":null,\"Items\":[],\"Scorable\":false,\"Score\":0,\"Visibility\":true,\"VisibilitySettings\":{\"Condition\":\"OR\",\"Rules\":[{\"Id\":\"X1234\",\"Value\":\"Yes\"},{\"Id\":\"X1222\",\"Value\":\"Yes\"}]},\"KMRs\":false,\"KMRsSettings\":[],\"Docs\":false,\"DocsSettings\":[],\"AutoFill\":true,\"AutoFillSettings\":{\"Value\":\"#999999\",\"Condition\":\"AND\",\"Rules\":[{\"Id\":\"X1234\",\"Value\":\"No\"},{\"Id\":\"X1234\",\"Value\":\"No\"}]}}";
RadzenUIElement element = JsonConvert.DeserializeObject<RadzenUIElement>(UIElement);
Console.WriteLine("UIElement " + element.Name);
foreach (var item in element.VisibilitySettings.Rules)
{
Console.WriteLine( item.Value.ToString());
}
string RadzenPanel = "{\"RadzenPanel\":{\"Id\":\"asfdgsertw34t43t34\",\"RadzenUiElement\":{\"Name\":\"X1144\",\"Order\":1,\"Tvalue\":\"int\",\"BindValue\":null,\"Default\":null,\"Disabled\":false,\"Mandatory\":true,\"MandatoryMessage\":\"this is a mandatory field\",\"Label\":\"<B> THIS is a HTML</b> label\",\"ToolTip\":\"just a tooltip\",\"PolicyProcess\":[{\"URL\":\"https://google.com\"}],\"Type\":\"RadzenColorPicker\",\"TypeOptions\":[{\"Name\":\"showHSV\",\"Value\":\"True\"},{\"Name\":\"showRGBA\",\"Value\":\"True\"},{\"Name\":\"ShowColors\",\"Value\":\"True\"},{\"Name\":\"showButton\",\"Value\":\"True\"}],\"ItemsType\":null,\"Items\":[],\"Scorable\":false,\"Score\":0,\"Visibility\":true,\"VisibilitySettings\":{\"Condition\":\"OR\",\"Rules\":[{\"Id\":\"X1234\",\"Value\":\"Yes\"},{\"Id\":\"X1222\",\"Value\":\"Yes\"}]},\"KMRs\":false,\"KMRsSettings\":[],\"Docs\":false,\"DocsSettings\":[],\"AutoFill\":true,\"AutoFillSettings\":{\"Value\":\"#999999\",\"Condition\":\"AND\",\"Rules\":[{\"Id\":\"X1234\",\"Value\":\"No\"},{\"Id\":\"X1234\",\"Value\":\"No\"}]}}}}";
RadzenPanel panels = JsonConvert.DeserializeObject<RadzenPanel>(RadzenPanel);
Console.WriteLine("elements in panels " + panels.Id);
the output from this code is below;
UIElement X1144
Yes
Yes
elements in panels
as i progress i'm looking to enhance the RadzenPanel to hold an array of the UIElements, but right now i cannot get it to parse a single item..
the object structure looks like this;
public class RadzenPanel
{
public string Id { get; set; }
public RadzenUIElement RadzenUiElement { get; set; }
}
public class RadzenUIElement
{
public string Name { get; set; }
public int Order { get; set; }
public string Tvalue { get; set; }
public string BindValue { get; set; }
public string Default { get; set; }
public bool Disabled { get; set; }
public bool Mandatory { get; set; }
public string MandatoryMessage { get; set; }
public string Label { get; set; }
public string ToolTip { get; set; }
public PolicyProcessLink[] PolicyProcess{ get; set; }
public string Type { get; set; }
public TypeOptions[] TypeOptions { get; set; }
public string ItemsType { get; set; }
public Items[] Items { get; set; }
public bool Scorable { get; set; }
public double ContributionScore { get; set; }
public bool Visibility { get; set; }
public VisibilitySettings VisibilitySettings { get; set; }
public bool KMRs { get; set; }
public KMRsSettings[] KMRsSettings { get; set; }
public bool Docs { get; set; }
public DocsSettings[] DocsSettings{ get; set; }
public bool AutoFill { get; set; }
public AutoFillSettings AutoFillSettings { get; set; }
}
public class PolicyProcessLink
{
public string URL { get; set; }
}
public class TypeConstants
{
public const string RadzenCheckbox = "RadzenCheckbox";
public const string RadzenCheckboxList = "RadzenCheckboxList";
public const string RadzenColorPicker = "RadzenColorPicker";
public const string RadzenDatePicker = "RadzenDatePicker";
public const string RadzenDropDown = "RadzenDropDown";
}
public class TypeOptions
{
public string Name { get; set; }
public string Value { get; set; }
}
public class Items
{
public string Name { get; set; }
public string Value { get; set; }
public string BGColor { get; set; }
public string TColor { get; set; }
public bool IsScore { get; set; }
public double Score { get; set; }
public bool IsNa { get; set; }
public string KMRIndicator{ get; set; }
public string DocsIncicator { get; set; }
}
public class VisibilitySettings
{
public bool Value { get; set; }
public string Condition { get; set; }
public Rules[] Rules { get; set; }
}
public class Rules
{
public string Id { get; set; }
public string Value { get; set; }
}
public class KMRsSettings
{
public Guid Id { get; set; }
public double Weighting { get; set; }
}
public class DocsSettings
{
public Guid Id { get; set; }
public double Weighting { get; set; }
}
public class AutoFillSettings
{
public string Value { get; set; }
public string Condition { get; set; }
public Rules[] Rules { get; set; }
}
not sure what the exact problem was, but i solved it by working through the c# model and progressively built the JSON to suit.
the full debug process started with an approach that debugged the core element. RadzenUiElement (bottom up) followed by building out the wrapper for the whole lot top down.
I am getting Json data from a web server, but when I try to deserialize it to objects, I am not getting any data. The Json string looks like this:
{"success":true,"data":[{"Id":6,"CustomerGuid":"70b390d8-82d5-4bba-aa68-fc8268a1b1ff","UserName":"victoria_victoria#nopCommerce.com","Email":"victoria_victoria#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472393)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472393)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":5,"CustomerGuid":"eb9e6f24-f362-4c10-942a-366e2919dc11","UserName":"brenda_lindgren#nopCommerce.com","Email":"brenda_lindgren#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472363)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472363)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":4,"CustomerGuid":"9f46dbae-6942-410c-90b8-9b38a0890064","UserName":"james_pan#nopCommerce.com","Email":"james_pan#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472317)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472317)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":3,"CustomerGuid":"6277386b-13ee-427b-9cfe-4ebfa487c340","UserName":"arthur_holmes#nopCommerce.com","Email":"arthur_holmes#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472253)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472253)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":2,"CustomerGuid":"241f45f1-b38c-4e22-8c5a-743fa3276620","UserName":"steve_gates#nopCommerce.com","Email":"steve_gates#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472207)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472207)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":1,"CustomerGuid":"a940dc03-5f52-47d2-9391-8597b3b31cf2","UserName":"tony#lakesideos.com","Email":"tony#lakesideos.com","CustomerRoles":[{"Id":1,"Name":"Administrators","SystemName":"Administrators"},{"Id":2,"Name":"Forum Moderators","SystemName":"ForumModerators"},{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":true,"Active":true,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":"71.185.255.7","CreatedOnUtc":"\/Date(1472933470783)\/","LastLoginDateUtc":"\/Date(1477522483903)\/","LastActivityDateUtc":"\/Date(1477523996553)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[{"Id":1,"StoreId":1,"ShoppingCartTypeId":1,"CustomerId":1,"ProductId":18,"AttributesXml":null,"CustomerEnteredPrice":0.0000,"Quantity":1,"CreatedOnUtc":"\/Date(1473801903447)\/","UpdatedOnUtc":"\/Date(1473803336207)\/","IsFreeShipping":false,"IsShipEnabled":true,"AdditionalShippingCharge":0.0000,"IsTaxExempt":false}]}]}
I created these classes from the recommendation given in this link:
recommendation
I used this to create the classes: json2csharp
Response class:
class Response
{
bool success;
IList<Customer> data;
}
Customer class:
class Customer
{
public int Id { get; set; }
public string CustomerGuid { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public List<CustomerRole> CustomerRoles { get; set; }
public object AdminComment { get; set; }
public bool IsTaxExempt { get; set; }
public int AffiliateId { get; set; }
public int VendorId { get; set; }
public bool HasShoppingCartItems { get; set; }
public bool Active { get; set; }
public bool Deleted { get; set; }
public bool IsSystemAccount { get; set; }
public object SystemName { get; set; }
public string LastIpAddress { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime? LastLoginDateUtc { get; set; }
public DateTime LastActivityDateUtc { get; set; }
public List<object> ExternalAuthenticationRecords { get; set; }
public List<object> ShoppingCartItems { get; set; }
}
CustomerRole class:
class CustomerRole
{
public int Id { get; set; }
public string Name { get; set; }
public string SystemName { get; set; }
}
ExternalAuthenticationRecord class:
class ExternalAuthenticationRecord
{
public int Id { get; set; }
public int CustomerId { get; set; }
public string Email { get; set; }
public object ExternalIdentifier { get; set; }
public object ExternalDisplayIdentifier { get; set; }
public object OAuthToken { get; set; }
public object OAuthAccessToken { get; set; }
public string ProviderSystemName { get; set; }
}
ShoppingCartItem class:
class ShoppingCartItem
{
public int Id { get; set; }
public int StoreId { get; set; }
public int ShoppingCartTypeId { get; set; }
public int CustomerId { get; set; }
public int ProductId { get; set; }
public object AttributesXml { get; set; }
public double CustomerEnteredPrice { get; set; }
public int Quantity { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime UpdatedOnUtc { get; set; }
public bool IsFreeShipping { get; set; }
public bool IsShipEnabled { get; set; }
public double AdditionalShippingCharge { get; set; }
public bool IsTaxExempt { get; set; }
}
I am using this statement to deserialzie the Json string: Response res = (Response)JsonConvert.DeserializeObject(customerJson, (typeof(Response)));
When I stop it in the debugger, it shows "res" as data: null and success: false.
I am not getting any errors. It is just not giving me the data from the Json string.
Any help that anybody can provide to figure out why I'm not getting the data I want in "res", would be gratefully appreciated.
Thanks,
Tony
The problem is related to the accessibility level in your Response class. By default the fields, property and method are private so JsonConvert is not able to fill the properties.
Change the class as follow:
class Response
{
public bool success {get; set;}
public IList<Customer> data {get; set;}
}
And it wil works.
Another improvement is related to the JsonConvert use. To avoid the explicit cast use this type conversion: JsonConvert.DeserializeObject<T>(string) where T will be Response
I'm writing simple imageviewer for one imageboard. I'm using these 2 classes for navigation(navigation parameter for Frame.Navigate() method) in my app:
public class KonaParameter
{
public int page { get; set; }
public string tags { get; set; }
public KonaParameter()
{
page = 1;
}
}
public class Post
{
public int id { get; set; }
public string tags { get; set; }
public int created_at { get; set; }
public int creator_id { get; set; }
public string author { get; set; }
public int change { get; set; }
public string source { get; set; }
public int score { get; set; }
public string md5 { get; set; }
public int file_size { get; set; }
public string file_url { get; set; }
public bool is_shown_in_index { get; set; }
public string preview_url { get; set; }
public int preview_width { get; set; }
public int preview_height { get; set; }
public int actual_preview_width { get; set; }
public int actual_preview_height { get; set; }
public string sample_url { get; set; }
public int sample_width { get; set; }
public int sample_height { get; set; }
public int sample_file_size { get; set; }
public string jpeg_url { get; set; }
public int jpeg_width { get; set; }
public int jpeg_height { get; set; }
public int jpeg_file_size { get; set; }
public string rating { get; set; }
public bool has_children { get; set; }
public object parent_id { get; set; }
public string status { get; set; }
public int width { get; set; }
public int height { get; set; }
public bool is_held { get; set; }
public string frames_pending_string { get; set; }
public List<object> frames_pending { get; set; }
public string frames_string { get; set; }
public List<object> frames { get; set; }
public object flag_detail { get; set; }
}
The problem I faced is that suspending doesn't work. SuspensionManager throws "SuspensionManager failed" exception after await SuspensionManager.SaveAsync(); call(I googled that it's because of using complex types).
I tried to use string as a navigation parameter. It works, but I need more than 1 string for my parameter(List<string> doesn't work, I tried to use it).
How to suspend my app correctly?
The problem is that SuspensionManager uses Frame.GetNavigationState() to get the history of the Frame. It then tries to serialise the navigation history to a string, unfortunately it has no way to know how to serialise custom complex types as parameters like Post or KonaParameter and fails with an exception.
If you want to use SuspensionManager then you'll need to restrict yourself to simple types like int or string as parameters.
If you do need complex types then it's best to store them in some background service / repository with an identifier. You can then pass the identifier as the parameter.
The recommended approach is to serialize your "state" object, so it can be saved/restored as a string. You can use Json.NET to do this:
//save state
Post post = //...;
string state = JsonConvert.Serialize(post)
//restore state
Post post = JsonConvert.Deserialize<Post>(state);
If you want to use two objects (a Post and a KonaParameter), I'd consider creating an "aggregate" class that encapsulates both, and serializing/deserializing that instead:
public class State
{
public Post post {get; set;}
public KonaParameter param {get; set;}
}