在HighChartsMap上增加一个国家/地区的大小?

2j4z5cfb  于 2022-11-11  发布在  Highcharts
关注(0)|答案(1)|浏览(216)

我正在用Highcharts收藏的欧洲Map来绘制分区图。它很好,但马耳他太小了,人们很难看到它。所以我的问题是:有没有办法在Map上只增加一个国家的大小?我知道在Map上通常是用插图来完成的,但在这里我可以只增加大小,使它稍微更明显一些。举个例子,当我看这张Map时,例如马耳他(就在意大利南端西西里岛的下面)非常小:https://jsfiddle.net/7j9fq8h3/

// Prepare demo data
// Data is joined to map using value of 'hc-key' property by default.
// See API docs for 'joinBy' for more info on linking data and map.
var data = [
    ['dk', 0],
    ['fo', 1],
    ['hr', 2],
    ['nl', 3],
    ['ee', 4],
    ['bg', 5],
    ['es', 6],
    ['it', 7],
    ['sm', 8],
    ['va', 9],
    ['tr', 10],
    ['mt', 11],
    ['fr', 12],
    ['no', 13],
    ['de', 14],
    ['ie', 15],
    ['ua', 16],
    ['fi', 17],
    ['se', 18],
    ['ru', 19],
    ['gb', 20],
    ['cy', 21],
    ['pt', 22],
    ['gr', 23],
    ['lt', 24],
    ['si', 25],
    ['ba', 26],
    ['mc', 27],
    ['al', 28],
    ['cnm', 29],
    ['nc', 30],
    ['rs', 31],
    ['ro', 32],
    ['me', 33],
    ['li', 34],
    ['at', 35],
    ['sk', 36],
    ['hu', 37],
    ['ad', 38],
    ['lu', 39],
    ['ch', 40],
    ['be', 41],
    ['kv', 42],
    ['pl', 43],
    ['mk', 44],
    ['lv', 45],
    ['by', 46],
    ['is', 47],
    ['md', 48],
    ['cz', 49]
];

// Create the chart
Highcharts.mapChart('container', {
    chart: {
        map: 'custom/europe'
    },

    title: {
        text: 'Highmaps basic demo'
    },

    subtitle: {
        text: 'Source map: <a href="http://code.highcharts.com/mapdata/custom/europe.js">Europe</a>'
    },

    mapNavigation: {
        enabled: true,
        buttonOptions: {
            verticalAlign: 'bottom'
        }
    },

    colorAxis: {
        min: 0
    },

    series: [{
        data: data,
        name: 'Random data',
        states: {
            hover: {
                color: '#BADA55'
            }
        },
        dataLabels: {
            enabled: false,
            format: '{point.name}'
        }
    }]
});

有没有办法通过API使用HighMaps来实现这一点,或者我最好的方法是创建我自己的GEOJSON文件?非常感谢您的回答,大卫

klh5stk1

klh5stk11#

您需要找到所需的路径元素,并对其使用平移和缩放变换。例如:

const malta = chart.series[0].points.find(p => p.name === 'Malta');
const bbox = malta.graphic.getBBox();
const centerX = bbox.width / 2 + bbox.x;
const centerY = bbox.height / 2 + bbox.y;
const scale = 3;

malta.graphic.attr({
    transform: 'translate(' +
        ((1 - scale) * centerX) + ', ' + ((1 - scale) * centerY) +
        ') scale(' + scale + ')'
}).toFront();

现场演示:https://jsfiddle.net/BlackLabel/ez6kr8a7/
**API参考:**https:api.highcharts.com/class-reference/Highcharts.SVGElement#attr
有用的线程:Scale path from center

相关问题