如何使用React Highcharts创建环形图?

huangapple go评论153阅读模式
英文:

How to get the doughnut chart using react highcharts?

问题

I tried to achieve this kind of chart.
但是我无法完全得到这个。而是得到了这个。

如何才能获得我想要的确切结果。

这是我尝试使用React Highcharts 做的。有人可以帮我吗?
先感谢了。

英文:

如何使用React Highcharts创建环形图?

I tried to achieve this kind of chart.
But I couldn't get this exactly. Instead of that I got this.如何使用React Highcharts创建环形图?

How can I get that exact thing that I want.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const getOptions = (type) =&gt; ({
  chart: {
    type:&#39;pie&#39;,
    width: 500,
    height: 300,
  },
  title: {
    text: _.startCase(`${type} chart`),
  },
  plotOptions: {
    series: {
      borderWidth: 0
    },
    type: &#39;pie&#39;,
    size: &#39;100%&#39;,
    innerSize: &#39;90%&#39;,
    dataLabels:{
      distance: &#39;-20px&#39;
    }
  },
  legend: {
    enabled: false
  },
  credits: {
    enabled: false
  },
  yAxis: {
    title: {
      text: &#39;Values&#39;,
    },
  },
  colors: [&#39;#FCE700&#39;, &#39;#F8C4B4&#39;, &#39;#f6e1ea&#39;, &#39;#B8E8FC&#39;, &#39;#BCE29E&#39;],
  series: [
    {
      data: [{
        y: 61.41,
        selected: true
    },{
        y: 20,
        selected: true
    }
  ],
      size: &#39;100%&#39;,
      innerSize: &#39;80%&#39;,
      dataLabels: {
        enabled: false,
        labelConnector: false,
      }
    },
  ],
});

function App() {
  return (
    &lt;div&gt;
      &lt;HighchartsReact highcharts={Highcharts} options={getOptions(&#39;pie&#39;)} /&gt;
    &lt;/div&gt;
  );
}

<!-- end snippet -->

This is what I tried using react highcharts. Can anyone please help me with this.!
Thanks in advance.

答案1

得分: 0

以下是您想要实现的图表的简化示例:

let data = 81;
Highcharts.chart(container, {
  colors: ['#F2BD27', '#222222'],
  title: {
    text: data + '%',
    verticalAlign: 'middle'
  },
  plotOptions: {
    pie: {
      dataLabels: {
        enabled: false
      },
      borderWidth: 0
    }
  },
  series: [{
    type: 'pie',
    innerSize: '95%',
    data: [data, 100 - data]
  }]
});

演示链接:
https://codesandbox.io/s/highcharts-react-demo-forked-yr9zgf

英文:

Here is a simplified example of the chart you want to achieve:

let data = 81;
Highcharts.chart(container, {
  colors: [&#39;#F2BD27&#39;, &#39;#222222&#39;],
  title: {
    text: data + &#39;%&#39;,
    verticalAlign: &#39;middle&#39;
  },
  plotOptions: {
    pie: {
      dataLabels: {
        enabled: false
      },
      borderWidth: 0
    }
  },
  series: [{
    type: &#39;pie&#39;,
    innerSize: &#39;95%&#39;,
    data: [data, 100 - data]
  }]
});

Demo:
https://codesandbox.io/s/highcharts-react-demo-forked-yr9zgf

huangapple
  • 本文由 发表于 2023年7月20日 13:16:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定