如何在highcharts.js中创建一个浮动柱状图?

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

How to create a floating bar chart in highcharts.js?

问题

I'm using highcharts.js 10.3.3,但似乎无法添加悬浮柱状图(series)。我看到它们有一个'columnrange'数据类型,这正是我想要的,但我需要它横向而不是纵向运行。我似乎找不到'barrange'的等效项。理想情况下,我只需为系列中的每个数据点指定最左边的点和最右边的点:

series: [
  {
    name: "My series",
    data: [[100, 150], [300, 450]]
  }
]
英文:

I'm using highcharts.js 10.3.3 and I can't seem to add a floating bar for a series. I see they have a 'columnrange' datatype which is what I'm looking for but I need it to run horizontally instead of vertically. I can't seem to find the 'barrange' equivalent. Ideally, I'd just specify the left-most point and right-most point for each datapoint in my series:

series: [
  {
    name: "My series",
    data: [[100, 150], [300, 450]]
  }
]

答案1

得分: 1

我已找到解决方法。您需要使用'low'字段来指定最左侧的点:

let chart;
document.addEventListener('DOMContentLoaded', () => {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'bar',
        },
        legend: {
            enabled: false
        },
        series: [{
            data: [{
                y: 10,
                low: 5
            },{
                y: 2,
                low: 8
            },{
                y: 4,
                low: 7.5
            }]
        }]
    });
});
<div id="container" style="height: 400px"></div>
<script src="https://code.highcharts.com/10.3.3/highcharts.js"></script>
英文:

I figured it out. You need to use the 'low' field to specify the left-most point:

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

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

let chart;
document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt; {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: &#39;container&#39;,
            defaultSeriesType: &#39;bar&#39;,
        },
        legend: {
            enabled: false
        },
        series: [{
            data: [{
                y: 10,
                low: 5
            },{
                y: 2,
                low: 8
            },{
                y: 4,
                low: 7.5
            }]
        }]
    });
});

<!-- language: lang-html -->

&lt;div id=&quot;container&quot; style=&quot;height: 400px&quot;&gt;&lt;/div&gt;
&lt;script src=&quot;https://code.highcharts.com/10.3.3/highcharts.js&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

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

发表评论

匿名网友

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

确定