High-quality charts use series labels as x-axis categories

I have a simple single-chip diagram where I load data using json. In my fiddle, I just defined json data as a static variable for simplicity, but the premise is the same.

The json data forms the basis for all the properties of the series, including the name and formatted in a way that is consistent with many examples that I saw:

var json = [{
    "name": "Currency Allocation",
    "data": [
        ["gbp", 0.7053985],
        ["usd", 0.17856322],
        ["eur", 0.06901525],
        ["chf", 0.00135777],
        ["jpy", 0.00815169],
        ["em_asia", 0.02821377],
        ["other", 0.00982446]
    ]
}];

I would like the label, which is the first element in each submatrix data, to be the x-axis category for the chart. However, apparently, I have to define the categories of the x axis separately under cht.xAxis.categories. Is there a way to avoid this and just use the categories in my data?

xAxis.categories, x

+4
1

chart.events.load series[0].data. , , , xAxis. :

var seriesData = this.series[0].data;
var tCategories = [];
for (i = 0; i < seriesData.length; i++) {
    tCategories.push(seriesData[i].name);
}
this.xAxis[0].setCategories(tCategories);

Live .

xAxis.type 'category':

"xAxis": {
    "type": "category"
},

Live .

+8

Source: https://habr.com/ru/post/1545104/


All Articles