Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, can anyone please help me with a sample c# code for creating bar chart on qliksense.
I am able to create an app, sheet, dimensions and measures on qlik sense using c#, but not sure how to create barchart. I have seen documentation, but unable to find the correct samples.
In theory it's all about creating a generic object with the right set of properties. The right set of properties can be rather hard to figure out though, but the easiest way is to look at the properties of an existing bar chart and use that as a template. There is also this page that can help you figure out which properties are available: https://qlik.dev/apis/javascript/sn-bar-chart/
If you want to place the chart in a sheet, then you'll need to place it in the sheet as well. Same thing there: there is no absolute documentation of how to do this, so reverse engineering the properties used by the client is the best tip I can offer. This is all part of the client functionality and not really something that is handled by the engine.
If you want to look at properties of existing objects, then I can recommend this tool:
https://community.qlik.com/t5/Qlik-Sense-Documents/Qlik-Explorer-for-Developers/ta-p/1949809
You can also activate the developer menu that allows you to inspect the properties directly in the client:
https://community.qlik.com/t5/Design/Developer-menu-in-Qlik-Sense-client/ba-p/1471915
In theory it's all about creating a generic object with the right set of properties. The right set of properties can be rather hard to figure out though, but the easiest way is to look at the properties of an existing bar chart and use that as a template. There is also this page that can help you figure out which properties are available: https://qlik.dev/apis/javascript/sn-bar-chart/
If you want to place the chart in a sheet, then you'll need to place it in the sheet as well. Same thing there: there is no absolute documentation of how to do this, so reverse engineering the properties used by the client is the best tip I can offer. This is all part of the client functionality and not really something that is handled by the engine.
If you want to look at properties of existing objects, then I can recommend this tool:
https://community.qlik.com/t5/Qlik-Sense-Documents/Qlik-Explorer-for-Developers/ta-p/1949809
You can also activate the developer menu that allows you to inspect the properties directly in the client:
https://community.qlik.com/t5/Design/Developer-menu-in-Qlik-Sense-client/ba-p/1471915
Hi,
I was trying to create a waterfallchart using dot net SDK and saw WaterfallchartProperties doesn't have a definition for "DataPoint" and "DimensionAxis", for which I was not able to see the chart in client side hub after creating sheet. This is a bug for sure. These properties are present in other types like linecharts, barcharts but not waterfall!
private static ISheet CreateSheets(IApp application, List<SheetCell> listOfCells)
{
return application.CreateSheet("Sheet-abc",
new SheetProperties { StateName = "abc", Rank = 0, Cells = listOfCells, MetaDef = new MetaAttributesDef { Title = "Abc", Description = "" } });
}
private static IGenericObject CreateWaterfallChart(ISheet sheet, NxInfo infoVisual)
{
return sheet.CreateChild<WaterfallChart>(new GenericObjectProperties() { Info = infoVisual });
}
After I set it explicitly, I was able to see the chart in my app. Now I am not sure how to set the values. Should I deserialize json and create c# classes?
child.Properties.Set("dimensionAxis", "");
child.Properties.Set("dataPoint", "");
snippet from Json:
No you don't really need to create C# classes. The .NET SDK includes a class called "AbstractStructure" whose main purpose is to provide a typed interface for the inherently untyped JSON structures that are used to define object properties. The following two links can tell you more:
https://help.qlik.com/en-US/sense-developer/February2024/Subsystems/NetSDKAPI/Content/Sense_NetSDKAP...
https://help.qlik.com/en-US/sense-developer/February2024/Subsystems/NetSDKAPI/Content/Sense_NetSDKAP...
There are generic "Set" and "Get" methods in that class for setting properties, and all the client object types that are available in the SDK simply extends this class and provides properties for translating C# structures to JSON and back. You don't have to go through such a class though, you can use the "Set" and "Get" methods directly. In your case you could do something like this to set the two "dimentionsAxis" and "dataPoint" properties in your "GenericObjectProperties" instance:
var o = app.GetGenericObject("<objId>");
var props = o.GetProperties();
var dimensionAxis = new DimensionAxis { Show = DimensionAxisShow.Labels, Dock = DimensionAxisDock.Near, Label = DimensionAxisLabel.Tilted };
var dataPoint = new BarchartDataPoint { ShowLabels = true };
props.Set("dimensionAxis", dimensionAxis);
props.Set("dataPoint", dataPoint);
o.SetProperties(props);
Thanks a bunch, now I know how to steal properties from other visual types and set them using abstract structure (if not present in the object I am trying to create). But what if I wanted to pass the full property tree of an object (propertyName:qProperty)? I do have the json of the object stored in a file. I tried using object.SetFullPropertyTree method which takes GenericObjectEntry "Property" as a parameter. It is a GenericObjectProperty which doesn't let me pass deserialized json. Tried below, no success:
var chart = app.GetGenericObject(objectId);
var props = chart.GetProperties();
var json="json";//for example
props.Set("qProperty", JsonConvert.DeserializeObject(json));
chart.SetProperties(props); //not adding hypercubes, json has qInfo,qhypercubedef
OR
chart.SetFullPropertyTree(new GenericObjectEntry() { Property = JsonConvert.DeserializeObject(json) });//error
The method "SetFullPropertyTree" sets the properties of the generic object and all its children. It looks to me like you just want to do "SetProperties" here, and in that case you could do something like this:
var chart = app.GetGenericObject(objectId);
var json = "json";//for example
var jObj = JObject.Parse(json);
var absStruct = new AbstractStructure(jObj);
var props = absStruct.As<GenericObjectProperties>();
chart.SetProperties(props);
I've written all the steps on separate lines here to be as clear as possible. The steps are:
You could of course inline it all like this:
var props = new AbstractStructure(JObject.Parse(json)).As<GenericObjectProperties>();
Thank you so much for the help. It did work as expected.