Понимание `treemap.data.label.formatter` в ECharts Baidu - PullRequest
0 голосов
/ 23 мая 2018

В документации от ECharts для treemap.data.label.formatter это объясняется следующим образом:

{@xxx}: the value of a dimension named'xxx', for example,{@product}refers the value of'product'` dimension。

Предположим, у меня есть данные, как показано ниже:

    data: [
            { 
                name: 'Region1',
                children: [
                    {
                         name: 'Region1-Country1',
                         // Option 1; I can make this work by using `formatter: '{b} brand count => {@[1]}'`

                         value: [800, 8], //here, '1000' is $ spend and '8' is brand count
                         // Option 2
                         value: {'brand':8, 'value':800},

                         // Option 3
                         brand: 8,
                         label: {
                                 show: true,
                                 formatter: '{b} brand count => {@??}' // WHAT should I use after '@'?
                        },
                         children: [
                            { name: 'Region1-Country1-Brand1', value: 200 },
                            { name: 'Region1-Country1-Brand2', value: 500 },
                         ]
                    },
                    {
                         name: 'Region1-Country2', 
                         value: 500, 
                         children: [
                            { name: 'Region1-Country2-Brand1', value: 100 },
                            { name: 'Region1-Country2-Brand2', value: 200 },
                            { name: 'Region1-Country2-Brand3', value: 200 },
                         ]
                    },
                ]
            },
       ]

На основеПо объяснению в документации выше, как мне подготовить массив data, чтобы я мог использовать formatter: '{b} brand count => {@brand}' и показать Region1-Country1 brand count => 8 на нарисованной карте?

1 Ответ

0 голосов
/ 23 мая 2018

Я думаю, что нашел ответ.Публикация здесь, чтобы поделиться с сообществом.

Нам нужно установить dimensions в series вместо series.data.Другими словами, если мы сделаем что-то вроде этого:

    series: [{
        name: 'Root',
        type: 'treemap',
        dimensions: ['value','brand'],
        visibleMin: 300,
        leafDepth: 2, 
        levels: [...] // skipped the details for `levels` here
        data: [
                { 
                    name: 'Region1',
                    brand: 9,
                    children: [
                        {
                             name: 'Region1-Country1',
                             value: [1000,8], // we can define dimensions like here: https://ecomfe.github.io/echarts-doc/public/en/option.html#dataset.dimensions
                            label: {
                            show: true,
                                formatter: '{b} brand count => {@brand}',
                            },
                             children: [
                                { name: 'Region1-Country1-Brand1', value: 200 },
                                { name: 'Region1-Country1-Brand2', value: 500 },
                             ]
                        },
                    ]
                },
              ]
            }]

Это сработает (я проверял это).Я пришел к этому ответу, прочитав этот в другой части документации ECharts.

...