如何根据以下数据绘制柱状图或类似时间线的图表。

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

How to draw a column/bar graph or something like timeline from the following data

问题

从上面的数据中,需要绘制一个时间轴,其中不同颜色表示滚筒经过的次数。

尝试过以下的highcharts:

  1. 柱状图
  2. 热力图
  3. 树状图

但未能如预期般生成结果。

英文:

I have the following data如何根据以下数据绘制柱状图或类似时间线的图表。

From the above data the need is to draw a timeline of the vechicle with different color for differnet number of times the rollers passed i.e.
如何根据以下数据绘制柱状图或类似时间线的图表。

I am unable to map the data points on chart or some vertical time line

Have tried using following highcharts:

  1. column chart
  2. heat maps
  3. treemap

But unable to generate results as expected

答案1

得分: 1

你可以将它制作成一个堆叠柱状图,只需一个柱子:

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Distances',
        align: 'left',
    },
    xAxis: {
        categories: [''],
    },
    yAxis: {
        min: 0,
        title: {
            text: 'distance in m'
        },
        stackLabels: {
            enabled: true,
            style: {
                fontWeight: 'bold',
                textOutline: 'none'
            }
        }
    },
    legend: {
        layour: 'horizontal',
        anchor: 'right',
        verticalAlign: 'bottom',
        borderWidth: 1,
        shadow: false
    },
    tooltip: {
        pointFormatter(original){ 
            return `<span style="color:${this.color}">●</span> from: ${this.stackY-this.y} to: ${this.stackY}`;
        }
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                //enabled: true
            }
        }
    },
    series: [
    {
        name: '2',
        data: [62],
        color: 'orange',
        showInLegend: false
    },
    {
        name: '1',
        data: [48],
        color: 'red',
        showInLegend: false
    },{
        name: '2',
        data: [26],
        color: 'orange',
        showInLegend: false
    },{
        name: '4',
        data: [49],
        color: 'green'
    },{
        name: '3',
        data: [2],
        color: 'darkgreen'
    },{
        name: '2',
        data: [7],
        color: 'orange',
        showInLegend: false
    },{
        name: '3',
        data: [2],
        color: 'red',
        showInLegend: false
    },{
        name: '2',
        data: [45],
        color: 'orange'
    },{
        name: '1',
        data: [10],
        color: 'red'
    },]
});
<div id="container" style="width:250px"></div>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
英文:

You can make it a column-stacked chart with just one column:

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

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

Highcharts.chart(&#39;container&#39;, {
chart: {
type: &#39;column&#39;
},
title: {
text: &#39;Distances&#39;,
align: &#39;left&#39;,
},
xAxis: {
categories: [&#39;&#39;],
},
yAxis: {
min: 0,
title: {
text: &#39;distance in m&#39;
},
stackLabels: {
enabled: true,
style: {
fontWeight: &#39;bold&#39;,
textOutline: &#39;none&#39;
}
}
},
legend: {
layour: &#39;horizontal&#39;,
anchor: &#39;right&#39;,
//x: 0,
verticalAlign: &#39;bottom&#39;,
borderWidth: 1,
shadow: false
},
tooltip: {
pointFormatter(original){ 
return `&lt;span style=&quot;color:${this.color}&quot;&gt;●&lt;/span&gt; from: ${this.stackY-this.y} to: ${this.stackY}`;
}
},
plotOptions: {
column: {
stacking: &#39;normal&#39;,
dataLabels: {
//enabled: true
}
}
},
series: [
{
name: &#39;2&#39;,
data: [62],
color: &#39;orange&#39;,
showInLegend: false
},
{
name: &#39;1&#39;,
data: [48],
color: &#39;red&#39;,
showInLegend: false
},{
name: &#39;2&#39;,
data: [26],
color: &#39;orange&#39;,
showInLegend: false
},{
name: &#39;4&#39;,
data: [49],
color: &#39;green&#39;
},{
name: &#39;3&#39;,
data: [2],
color: &#39;darkgreen&#39;
},{
name: &#39;2&#39;,
data: [7],
color: &#39;orange&#39;,
showInLegend: false
},{
name: &#39;3&#39;,
data: [2],
color: &#39;red&#39;,
showInLegend: false
},{
name: &#39;2&#39;,
data: [45],
color: &#39;orange&#39;
},{
name: &#39;1&#39;,
data: [10],
color: &#39;red&#39;
},]
});

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

&lt;div id=&quot;container&quot; style=&quot;width:250px&quot;&gt;&lt;/div&gt;
&lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/modules/accessibility.js&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

Of course, the data in the series can be generated by a function taking the data from an original format and automatting some structures, like adding showInLegend: false for the categories that were already represented in the legend.

huangapple
  • 本文由 发表于 2023年5月7日 14:36:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192513.html
匿名

发表评论

匿名网友

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

确定