admin管理员组文章数量:1400182
Hi I want to add a horizontal line to my Barchart. This is the Code of my chart:
var singleBarOptions = {
scaleBeginAtZero: true,
scaleShowGridLines: true,
scaleGridLineColor: "rgba(0,0,0,.05)",
scaleGridLineWidth: 1,
barShowStroke: true,
barStrokeWidth: 1,
barValueSpacing: 5,
barDatasetSpacing: 1,
responsive: true
};
var singleBarData = {
labels: ["2010", "2011", "2012", "2013", "2014", "2015", "2016"],
datasets: [
{
label: "My Second dataset",
fillColor: "rgba(0,191,255,0.5)",
strokeColor: "rgba(0,191,255,0.8)",
highlightFill: "rgba(100,149,237,0.75)",
highlightStroke: "rgba(100,149,237,1)",
data: [60, 50, 40, 30, 20, 10, 20]
}
]
};
var ctx = document.getElementById("singleBarOptions").getContext("2d");
var myNewChart = new Chart(ctx).Bar(singleBarData, singleBarOptions);
Is there an easy way to draw this line? It would also be nice if I could change the position of the line later on.
There are solutions here on stackoverflow, but they don't deal with settings.
Hi I want to add a horizontal line to my Barchart. This is the Code of my chart:
var singleBarOptions = {
scaleBeginAtZero: true,
scaleShowGridLines: true,
scaleGridLineColor: "rgba(0,0,0,.05)",
scaleGridLineWidth: 1,
barShowStroke: true,
barStrokeWidth: 1,
barValueSpacing: 5,
barDatasetSpacing: 1,
responsive: true
};
var singleBarData = {
labels: ["2010", "2011", "2012", "2013", "2014", "2015", "2016"],
datasets: [
{
label: "My Second dataset",
fillColor: "rgba(0,191,255,0.5)",
strokeColor: "rgba(0,191,255,0.8)",
highlightFill: "rgba(100,149,237,0.75)",
highlightStroke: "rgba(100,149,237,1)",
data: [60, 50, 40, 30, 20, 10, 20]
}
]
};
var ctx = document.getElementById("singleBarOptions").getContext("2d");
var myNewChart = new Chart(ctx).Bar(singleBarData, singleBarOptions);
Is there an easy way to draw this line? It would also be nice if I could change the position of the line later on.
There are solutions here on stackoverflow, but they don't deal with settings.
Share Improve this question edited Oct 21, 2016 at 13:01 B5-NDDT asked Oct 19, 2016 at 8:33 B5-NDDTB5-NDDT 1871 gold badge3 silver badges16 bronze badges 4- Can you please put this in a fiddle and share the link?, – David R Commented Oct 19, 2016 at 8:36
- Possible duplicate of Chart.js - draw horizontal line – tektiv Commented Oct 20, 2016 at 9:32
- its not a duplicate, they only have a dataset. I don't know how to add my settings to their code. – B5-NDDT Commented Oct 21, 2016 at 13:00
- please create fiddle of the code u tried – Ashish Patel Commented Oct 21, 2016 at 13:04
1 Answer
Reset to default 5Yes, use the Annotations plugin:Chart.Annotation.js
annotation: {
annotations: [{
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: '26',
borderColor: 'tomato',
borderWidth: 1
}],
drawTime: "afterDraw" // (default)
}
Result:
Codepen: Chart.js Annotations BarChart
Note: I am using V 2.2.1, your syntax is I believe from a previous version, so I am only using your Data and some options.
本文标签: javascriptAdd horizontal Line to my chartjs BarchartStack Overflow
版权声明:本文标题:javascript - Add horizontal Line to my chart.js Barchart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744198849a2594869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论