gpt4 book ai didi

javascript - 如何使用chartJs中的折线图减小三 Angular 形的底部宽度?

转载 作者:行者123 更新时间:2023-12-02 21:08:26 26 4
gpt4 key购买 nike

我已经使用chartJs创建了折线图,现在它工作正常,但对我来说没有什么问题,实际上我想使用chartJs中的折线图来减少三 Angular 形的底部宽度>。怎么才能做到这一点?

尝试了什么:-

var presets = window.chartColors;
var utils = Samples.utils;
var inputs = {
min: 0,
max: 100,
count: 8,
decimals: 2,
continuity: 1
};

function generateData(config) {
return utils.numbers(Chart.helpers.merge(inputs, config || {}));
}

function generateLabels(config) {
return utils.months(Chart.helpers.merge({
count: inputs.count,
section: 3
}, config || {}));
}

var options = {
maintainAspectRatio: false,
spanGaps: false,
elements: {
line: {
tension: 0.000001
}
},
plugins: {
filler: {
propagate: false
}
},
scales: {
xAxes: [{
ticks: {
autoSkip: false,
maxRotation: 0
}
}]
}
};

[false, 'origin', 'start', 'end'].forEach(function(boundary, index) {
const canvas = document.getElementById('chart-' + index);
if(canvas)
{
utils.srand(8);
var ctx = canvas.getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: generateLabels(),
datasets: [{
backgroundColor: utils.transparentize(presets.red),
borderColor: presets.red,
//data: generateData(),
data: [0, 0, 40, 0,0, 50, 0, 0, 0],
label: 'Dataset',
fill: boundary
}]
},
options: Chart.helpers.merge(options, {
title: {
text: 'fill: ' + boundary,
display: true,
}
})
});
}
});
<!DOCTYPE html>
<html lang="en-US">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>area > boundaries | Chart.js sample</title>
<link rel="stylesheet" type="text/css" href="https://www.chartjs.org/samples/latest/style.css">
<script src="https://www.chartjs.org/dist/2.9.3/Chart.min.js"></script>
<script src="https://www.chartjs.org/samples/latest/utils.js"></script>
<script src="https://www.chartjs.org/samples/latest/charts/area/analyser.js"></script>
</head>

<body>
<div class="content">
<div class="wrapper col-2"><canvas id="chart-2"></canvas></div>
</div>


</body>

</html>

回答将不胜感激!

感谢您的努力!

最佳答案

您可以将xAxis定义为time caresian axis ,摆脱 data.labels 并将单个数据点指定为 objects with an x and y property

Please note that Chart.js uses Moment.js for the functionality of the time axis. Therefore you should use the bundled version of Chart.js that includes Moment.js in a single file.

new Chart('canvas', {
type: 'line',
data: {
datasets: [{
label: 'My Dataset',
data: [
{ x: '01-01', y: 0 },
{ x: '02-26', y: 0 },
{ x: '03-01', y: 40 },
{ x: '03-05', y: 0 },
{ x: '05-28', y: 0 },
{ x: '06-01', y: 50 },
{ x: '06-05', y: 0 },
{ x: '08-01', y: 0 }
],
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgb(255, 99, 132)',
lineTension: 0
}]
},
options: {
scales: {
xAxes: [{
type: 'time',
time: {
parser: 'MM-DD',
unit: 'month',
displayFormats: {
month: 'MMM'
},
tooltipFormat: 'MMM DD'
}
}]
}
}
});
canvas {
max-width: 400px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<canvas id="canvas" width="8" height="4"></canvas>

关于javascript - 如何使用chartJs中的折线图减小三 Angular 形的底部宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61161953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com