简体   繁体   English

ChartJs:是否可以在线显示较少或某个数据点?

[英]ChartJs: is it possible to show lesser or a certain data point on line?

For instance, the attached figure it is showing ALL points as circles .例如,附图将所有点显示为圆圈 What If I want to show the last data point on each line?如果我想在每行上显示最后一个数据点怎么办? is it possible?是否可以?

在此处输入图像描述

You can use a scriptable function for this:您可以为此使用可编写脚本的 function:

 var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: 'line', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], pointRadius: (context) => context.dataIndex == (context.chart.data.datasets[context.datasetIndex].data.length - 1)? 10: 0 // Default is 3, used 1- for more clarity }] }, options: { } });
 <script src="https://npmcdn.com/chart.js@4.2.0/dist/chart.umd.js"></script> <div class="myChartDiv"> <canvas id="myChart" width="600" height="400"></canvas> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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