如何设置echarts背景四个角的半径?

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

How to set the radius of the four corners of the echarts background?

问题

I have been learning how to use ECharts recently.
I want to change the radius of the four corners of the echarts background, like this:

Operating environment:
echarts: 5.4.2
vue3

I tried using three methods.
1. Added option attribute: borderRadius: [20, 20, 20, 20],

option = {
  backgroundColor: '#999',
  **borderRadius: [20, 20, 20, 20],**
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [120, 200, 150, 80, 70, 110, 130],
      type: 'bar'
    }
  ]
};

2. Set the radian of the echarts container itself.

<div ref="EnergyCalendar" style="border-radius: 20px; height: 320px; width: 100%;">
</div>

3. Wrap the div outside the echarts container and set the radius of the div.

<div style="border-radius: 20px;">
  <div ref="EnergyCalendar" style="height: 320px; width: 100%;">
  </div>
</div>

But none of these three methods are effective.

Can someone familiar with ECharts help explain how to implement this feature?
Thank you in advance for your answer!

英文:

I have been learning how to use ECharts recently.
I want to change the radius of the four corners of the echarts background, like this:

如何设置echarts背景四个角的半径?

Operating environment:
echarts: 5.4.2
vue3

I tried using three methods.
1. Added option attribute: borderRadius: [20, 20, 20, 20], (this is the answer from chatgpt)

option = {
  backgroundColor :&#39;#999&#39;,
  **borderRadius: [20, 20, 20, 20],**
  xAxis: {
    type: &#39;category&#39;,
    data: [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wed&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]
  },
  yAxis: {
    type: &#39;value&#39;
  },
  series: [
    {
      data: [120, 200, 150, 80, 70, 110, 130],
      type: &#39;bar&#39;
    }
  ]
};

2. Set the radian of the echarts container itself.

&lt;div ref=&quot;EnergyCalendar&quot; style=&quot;border-radius: 20px;height: 320px; width: 100%;&quot;&gt;
&lt;/div&gt;

3. Wrap the div outside the echarts container and set the radius of the div.

&lt;div style=&quot;border-radius: 20px;&quot;&gt;
  &lt;div ref=&quot;EnergyCalendar&quot; style=&quot;height: 320px; width: 100%;&quot;&gt;
  &lt;/div&gt;
&lt;/div&gt;

But none of these three methods are effective.

Can someone familiar with ECharts help explain how to implement this feature?
Thank you in advance for your answer!

答案1

得分: 1

如果使用 canvas 渲染器,您可以样式化容器内的 canvas 元素:

#chart-container canvas{
  border-radius: 20px
}

如果使用 svg 渲染器,您可以样式化容器内的 svg 元素:

#chart-container svg{
  border-radius: 20px
}

当然,您可以组合它们以涵盖两种情况。

英文:

If you use the canvas renderer, you may style the canvas element inside the container:

#chart-container canvas{
  border-radius: 20px
}

If you're using the svg renderer you may style the svg element inside the container:

#chart-container svg{
  border-radius: 20px
}

Of course, you may combine these, to cover both cases.

huangapple
  • 本文由 发表于 2023年5月22日 15:53:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304049.html
匿名

发表评论

匿名网友

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

确定