最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

highcharts - How to round both ends of bars in a bar chart? - Stack Overflow

programmeradmin8浏览0评论

I need a Highcharts bar chart with both ends (left and right) rounded, so I tried the config below, but only the right end of the bars is rounded.

I expected both ends to be rounded, as some Stack Overflow answers suggest that borderRadius: 8 should apply to both. However, in my case, only the right end is rounded.

Am I missing something? Is there a workaround for this?

    const data = [
    { category: 'Apples', value: 10 },
    { category: 'Bananas', value: 15 },
    { category: 'Oranges', value: 8 },
    { category: 'Grapes', value: 12 },
    { category: 'Peaches', value: 5 },
];

const chartOptions = {
    chart: {
        type: 'bar', // Horizontal bars
        height: 400,
        clip: false,
    },
    title: {
        text: 'Simple Horizontal Bar Chart',
    },
    xAxis: {
        categories: data.map(item => item.category), // Labels for each bar
        title: {
            text: 'Categories',
        },
    },
    yAxis: {
        title: {
            text: 'Values',
        },
    },
    plotOptions: {
        series: {
            borderRadius: 10, // ✅ Rounded edges on both ends
            pointPlacement: 'between',
        },
    },
    series: [
        {
            name: 'Data',
            data: data.map(item => item.value), // Numeric values for bars
        },
    ],
    legend: {
        enabled: false,
    },
};

I need a Highcharts bar chart with both ends (left and right) rounded, so I tried the config below, but only the right end of the bars is rounded.

I expected both ends to be rounded, as some Stack Overflow answers suggest that borderRadius: 8 should apply to both. However, in my case, only the right end is rounded.

Am I missing something? Is there a workaround for this?

    const data = [
    { category: 'Apples', value: 10 },
    { category: 'Bananas', value: 15 },
    { category: 'Oranges', value: 8 },
    { category: 'Grapes', value: 12 },
    { category: 'Peaches', value: 5 },
];

const chartOptions = {
    chart: {
        type: 'bar', // Horizontal bars
        height: 400,
        clip: false,
    },
    title: {
        text: 'Simple Horizontal Bar Chart',
    },
    xAxis: {
        categories: data.map(item => item.category), // Labels for each bar
        title: {
            text: 'Categories',
        },
    },
    yAxis: {
        title: {
            text: 'Values',
        },
    },
    plotOptions: {
        series: {
            borderRadius: 10, // ✅ Rounded edges on both ends
            pointPlacement: 'between',
        },
    },
    series: [
        {
            name: 'Data',
            data: data.map(item => item.value), // Numeric values for bars
        },
    ],
    legend: {
        enabled: false,
    },
};
Share Improve this question edited Mar 27 at 9:05 DarkBee 15.5k8 gold badges72 silver badges117 bronze badges asked Mar 27 at 9:03 user30077970user30077970 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Under this API doc you have link to example how to control border radius on both ends: https://api.highcharts/highcharts/series.column.borderRadius

Here is your config updated in relevant places:

{  
  chart: {
    ...,
    events: {
      load() {
        const chart = this;
        chart.update({
          plotOptions: {
            series: {
              borderRadius: {
                where: "all",
              },
            },
          },
        })
      },
    },
  },
  ...,
  plotOptions: {
    series: {
      borderRadius: {
        radius: 10,
      },
    },
  },
  ...
}

I hope you will find it useful.

Best,

发布评论

评论列表(0)

  1. 暂无评论