Dear Support Team, Dear Community,
First of all, thank you for taking your time to read through and answer my question related to X-Axis labeling in Contour.
I have input data with a custom dimension, which I want to have on my X-Axis. Therefore, as the procedure only provides indexed data points from 0 to N, I decided to go for a solution that accesses the keys, that are sent in the Json-Object and loop through.
xAxis: {
labels: {
formatter: function(d) {
return Object.keys(data.variable)[d];
}
}
},
Would there be another, more natural solution in contour, as I do feel that this is more of a workarround rather than a natural workflow in the library.
Furthermore I wanted to ask, if the X-Axis of a bar chart can also be set via the setData() or a comparable function. As the data object, that is passed is solely an array indexed from 0 onwards.
I have added the full code as a reference below.
Have a great day!
Julian
Flow.channel.variables.subscribe("variable", function(data) {
console.log("variable");
console.log(data);
console.log(data.variable);
var data_array = [];
var counter = 0;
for(var key in data.variable){
data_array[counter] = data.variable[key][0]
counter ++
};
$(function variable_chart() {
chart_test = document.getElementById("variable_chart");
console.log(chart_test);
contains_svg = chart_test.getElementsByTagName("svg");
if(contains_svg.length == 0){
variable_chart_object= new Contour({
el: '#variable_chart',
xAxis: {
labels: {
formatter: function(d) {
return Object.keys(data.variable)[d];
}
}
},
})
.cartesian()
.column(data_array)
.drawable()
.render();
} else {
console.log("update chart");
variable_chart_object.setData(data_array).render();
}
});
});