我可以根据图表中的给定阈值设置不同的填充颜色吗.js
Can I set different fill color based on a given threshold in Chart.js?
是否可以
为图表中高于或低于给定阈值的值使用不同的填充颜色.js(图表.js)?
我在 Chart 中找不到任何执行此操作的选项.js,以前有人做过这样的事情吗?我更喜欢使用图表.js而不是Highcharts。
像这样:高图表示例
.html
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
.js
$(function () {
$('#container').highcharts({
chart: {
type: 'area'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
},
yAxis: {
title: {
text: '$'
}
},
title: {
text: 'Win/Loss'
},
series: [{
name: 'Avg. ($)',
data: [546, 342, -234, -540, 103, -345],
threshold: -1,
negativeFillColor: 'rgba(255,0,0,0.5)',
fillColor: 'rgba(0,204,0,0.5)',
lineColor: 'rgba(0,0,0,1)',
marker: {
fillColor: 'rgba(255,255,255,1)',
lineColor: 'rgba(0,0,0,1)',
lineWidth: 1
}
},{
name: 'User ($)',
data: [-640, -665, -700, -640, -630, -623],
fillOpacity: 0,
lineColor: 'rgba(20, 94, 204, 1)',
marker: {
fillColor: 'rgba(255,255,255,1)',
lineColor: 'rgba(20, 94, 204, 1)',
lineWidth: 1
}
}]
});
});
我使用 gradientStroke 命令做了类似的事情,然后将其应用于 backgroundColor:
var ctx = document.getElementById("YearsExperience").getContext("2d");
var gradientStroke = ctx.createLinearGradient(0, 1200, 0, 0);
gradientStroke.addColorStop(0, "#80b6f4");
gradientStroke.addColorStop(0.2, "#94d973");
gradientStroke.addColorStop(0.4, "#80b6f4");
gradientStroke.addColorStop(1, "#94d973");
var YearsExperience = new Chart(ctx, {
type: 'bar',
data: { labels: ArrLabel[idx], datasets: [{ label: 'Years of experience', data: ArrData[idx], backgroundColor: gradientStroke }] },
options: { scales: { xAxes: [{gridLines: {display:false}}], yAxes: [{ ticks: { beginAtZero:true } }] }, events: ['none'],animation: { easing: "easeInOutBack" } }
});
可以在此处看到输出的示例:http://neophytte.mine.nu/portfolio/skills.html
相关文章:
- 如何设置html元素填充的动画
- 如何让iframe在设置负上边距后填充整个移动网页
- 如何为所有子元素设置填充
- 无法使用 Snap.SVG将“填充”属性设置为“继承”
- 设置图像以使用纸张.js填充画布
- 如何动态设置填充并在不刷新的情况下显示它
- 如何以类似于vivus.js的样式设置SVG填充和路径的动画
- 仅为父对象的填充设置动画
- 如何设置iframe以自动填充HTML中的空白正文空间
- 如何设置<选项>在用数据绑定填充的选择中='选项:[..]'
- 设置一个下拉填充到它's的值和文本在AngularJS和asp.net webApi中的编辑模式
- 根据两个元素的重叠宽度动态设置左填充
- 设置 AJAX 调用和填充下拉列表
- 画布填充从数字开始设置样式
- 设置要编辑的表单时下拉菜单未填充
- 使用 D3,如何设置轴路径和线条的属性(“填充”、“无”),而不是文本(不编辑样式表)
- 设置填充构件时砌体不起作用
- 没有设置填充颜色的条形图
- 在javascript中使用变量设置填充表单字段
- 如果我们在系列中有超过16个数据,如何设置填充和放置