简体   繁体   中英

How to set only min and max values in y-axis (chart js)

i have a problem, how can i to make a line chart that can show the y-axis of this way?

i attach an example in an image

在此处输入图片说明

It is only possible with the current master code, after the next release of chart.js this will be possible with using normal CDN's

Example of current master branch code:

 var options = { type: 'line', data: { labels: ["15/03/2020", "16/03/2020", "17/03/2020", "18/03/2020", "19/03/2020", "20/03/2020", "21/03/2020"], datasets: [{ label: 'Dataset 1', data: [10, 30, 50, 20, 25, 44, -10], borderColor: 'red', backgroundColor: 'red' }, { label: 'Dataset 2', data: [10, 30, 50, 20, 25, 44, -10], borderColor: 'blue', backgroundColor: 'blue', yAxisID: 'y2', } ] }, options: { scales: { y: { type: 'linear', position: 'left', stack: 'demo', ticks: { min: -20, max: 70 }, grid: { borderColor: 'red' }, title: { display: true, text: 'title1' } }, y2: { type: 'linear', offset: true, position: 'left', stack: 'demo', ticks: { min: -20, max: 70 }, grid: { borderColor: 'blue' }, title: { display: true, text: 'title2' } } } } } var ctx = document.getElementById('chartJSContainer').getContext('2d'); new Chart(ctx, options);
 <body> <canvas id="chartJSContainer" width="600" height="400"></canvas> <script src="https://www.chartjs.org/dist/master/chart.js"></script> </body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM