ChartJS 如何删除折线图背景中的网格线?

yfjy0ee7  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(386)

我正在处理一个React JS项目。在我的项目中,我需要创建折线图组件。我尝试使用Chart JS 2库来处理React JS。但是,现在我在定制折线图时遇到了一个小问题。我想删除背景中的网格和线条(屏幕截图)以及图表顶部的标签(我的第一个数据集)。

这是我的密码。

  1. const data = {
  2. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  3. datasets: [
  4. {
  5. label: 'My First dataset',
  6. fill: true,
  7. lineTension: 0.1,
  8. backgroundColor: '#edfce9',
  9. borderColor: '#3DAA1D',
  10. borderCapStyle: 'butt',
  11. borderDash: [],
  12. borderDashOffset: 0.0,
  13. borderJoinStyle: 'miter',
  14. pointBorderColor: '#3DAA1D',
  15. pointBackgroundColor: '#fff',
  16. pointBorderWidth: 1,
  17. pointHoverRadius: 5,
  18. pointHoverBackgroundColor: '#3DAA1D',
  19. pointHoverBorderColor: 'rgba(220,220,220,1)',
  20. pointHoverBorderWidth: 2,
  21. pointRadius: 1,
  22. pointHitRadius: 10,
  23. data: [65, 59, 80, 81, 56, 55, 40],
  24. showLine: true
  25. }
  26. ]
  27. };
  28. <Line data={data} />

我该怎么做?删除图表背景中的网格(线)并删除顶部的标签(我的第一个数据集)?

avwztpqn

avwztpqn1#

请查看文档。您可以在选项中禁用网格线(您必须添加)https://www.chartjs.org/docs/2.9.4/axes/cartesian/#common-configuration

  1. options: {
  2. scales: {
  3. yAxes: [
  4. gridLines: {
  5. display: false
  6. }
  7. ],
  8. xAxes: [
  9. gridLines: {
  10. display: false
  11. }
  12. ]
  13. },
  14. legend: {
  15. display: false
  16. }
  17. }

版本3:

  1. options: {
  2. scales: {
  3. x: {
  4. grid: {
  5. display: false
  6. }
  7. },
  8. y: {
  9. grid: {
  10. display: false
  11. }
  12. }
  13. }
  14. }
展开查看全部

相关问题