Man*_*her 40 javascript angularjs chart.js
好的,所以我有一个ChartJS折线图工作,直接填充来自我的数据库的数据.我现在需要的是摆脱每条线下面的颜色.[如下面的截图所示].
这是我的HTML:
<div ng-if="hasData">
<canvas id="line" class="chart chart-line" data="data" labels="labels" legend="true" series="series" options="options" click="onClick"></canvas>
<div>
Run Code Online (Sandbox Code Playgroud)
这是我的JS:
scope.labels = ['02:00','04:00','06:00', '08:00', '10:00', '12:00','14:00', '16:00', '18:00', '20:00', '22:00'];
scope.series = series;
scope.data = [volumesSelectedDate, volumesPeakDate, volumesModelCapacity];
scope.options = {
scaleOverride: true,
scaleStartValue: 0,
scaleSteps: 11,
scaleStepWidth: 6910,
}
scope.loadingDailyAppVolumes = false;
scope.hasData = true;
};
scope.onClick = function (points, evt) {
//console.log(points, evt);
};
Run Code Online (Sandbox Code Playgroud)
那么,我该怎么做呢?另外,我如何手动设置每一行的颜色?
例:
选定日期:蓝色,高峰日期:黄色,型号容量:灰色.
谢谢.
Jas*_*onK 58
在Chart.js文档中查看此部分.fill在数据集配置中将属性设置为false:
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
fill: false,
data: [1, 2, 3]
}]
};
Run Code Online (Sandbox Code Playgroud)
borderColor如果希望每一行具有不同的笔触颜色,请为该属性指定一个数组:
var myColors = ['red', 'green', 'blue']; // Define your colors
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
fill: false,
borderColor: myColors
data: [1, 2, 3]
}]
};
Run Code Online (Sandbox Code Playgroud)
aks*_*kar 22
当与Angular集成图表js时,下面的解决方案正在工作
$scope.options = {
scales: {
yAxes: [
{
id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left'
}
]
},
elements: {
line: {
fill: false
}
}
};
<canvas id="" class="col-sm-12 chart chart-line" chart-data="data"
chart-options="options" chart-colors="colors">
</canvas>
Run Code Online (Sandbox Code Playgroud)
我解决了这个问题.
第一步.html元素内部添加< - chart-colors ="colors",如下所示:
<canvas id="line" class="chart chart-line" data="data" labels="labels" chart-colors="colors" legend="true" series="series" options="options" click="onClick"></canvas>
Run Code Online (Sandbox Code Playgroud)
第二步.$ scope val colors添加如下:
$scope.colors = [{
backgroundColor : '#0062ff',
pointBackgroundColor: '#0062ff',
pointHoverBackgroundColor: '#0062ff',
borderColor: '#0062ff',
pointBorderColor: '#0062ff',
pointHoverBorderColor: '#0062ff',
fill: false /* this option hide background-color */
}, '#00ADF9', '#FDB45C', '#46BFBD'];
Run Code Online (Sandbox Code Playgroud)
祝好运!
小智 6
Just set the fill option to be false in the datasets options:
data: {
datasets: [{
label: "",
data: dataPoints,
borderColor: color ,
fill:false //this for not fill the color underneath the line
}]
},
Run Code Online (Sandbox Code Playgroud)
这对我有用:
$scope.color = [{
backgroundColor: 'transparent',
borderColor: '#F78511',
},];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47983 次 |
| 最近记录: |