Reactjs 如何在图表区域和图表线之间添加边距?

Reactjs 如何在图表区域和图表线之间添加边距?,reactjs,chart.js,react-chartjs,Reactjs,Chart.js,React Chartjs,我正在使用chart js,我制作了一个折线图。我尝试了多种方法并浏览了整个文档,但我找不到实现这一点的方法。 我尝试使用渐变在图表区域背景和线条之间添加一些空白。 我需要为这个小需求制作插件吗?我需要在线条和图表区域背景之间留一个边距或空白 function App() { var options = { // layout: { // padding: { // left: 50, // right: 0, // //

我正在使用chart js,我制作了一个折线图。我尝试了多种方法并浏览了整个文档,但我找不到实现这一点的方法。 我尝试使用渐变在图表区域背景和线条之间添加一些空白。 我需要为这个小需求制作插件吗?我需要在线条和图表区域背景之间留一个边距或空白

function App() {
  var options = {
    // layout: {
    //   padding: {
    //     left: 50,
    //     right: 0,
    //     // top: 100,
    //     bottom: 100
    //   }
    // },
    scales: {
      xAxes: [
        {
          gridLines: {
            drawOnChartArea: false,
            drawBorder: false
          },
          ticks: {
            display: false
          }
        }
      ],
      yAxes: [
        {
          gridLines: {
            drawOnChartArea: false,
            drawBorder: false
          },
          ticks: {
            display: false
          }
        }
      ]
    },
    maintainAspectRatio: false,
  };
  const data = canvas => {
    const ctx = canvas.getContext("2d");
    const gradient = ctx.createLinearGradient(0, 49, 0, 500);
    // gradient.addColorStop(0.6, "white");    
    gradient.addColorStop(0.21, "rgba(226,240,251,1)");
    gradient.addColorStop(0.54, "rgba(244,249,253,1)");
    gradient.addColorStop(0.8, "rgba(251,253,254,1)");

    return {
      labels: ["January", "February", "March", "April", "May", "June", "July"],
      datasets: [
        {
          label: "My First dataset",
          lineTension: 0.5,
          fill:true,
          backgroundColor: gradient,
          borderColor: "#347aeb",
          borderCapStyle: "butt",
          borderDash: [],
          borderWidth: 5,
          borderDashOffset: 0.0,
          borderJoinStyle: "round",
          pointBorderColor: "#347AEB",
          pointBackgroundColor: "white",
          pointBorderWidth: 5,
          pointHoverRadius: 5,
          pointHoverBackgroundColor: "white",
          pointHoverBorderColor: "rgba(220,220,220,1)",
          pointHoverBorderWidth: 2,
          pointRadius: 10,
          pointHitRadius: 10,

          // showLine: 0,
          data: [65, 59, 80, 81, 56, 55, 40]
        }
      ]
    };
  };

  return (

    
      <Line data={data} width={100} height={400} options={options}></Line>

  );
}


函数应用程序(){
变量选项={
//布局:{
//填充:{
//左:50,,
//右:0,,
////前100名,
//底数:100
//   }
// },
比例:{
xAxes:[
{
网格线:{
drawOnChartArea:错误,
抽边线:假
},
滴答声:{
显示:假
}
}
],
雅克斯:[
{
网格线:{
drawOnChartArea:错误,
抽边线:假
},
滴答声:{
显示:假
}
}
]
},
MaintaintAspectRatio:false,
};
const data=canvas=>{
const ctx=canvas.getContext(“2d”);
常数梯度=ctx.createLinearGradient(0,49,0,500);
//渐变。添加颜色停止(0.6,“白色”);
渐变色阻(0.21,“rgba(226240251,1)”;
梯度。addColorStop(0.54,“rgba(244249253,1)”;
梯度。addColorStop(0.8,“rgba(251253254,1)”);
返回{
标签:[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”],
数据集:[
{
标签:“我的第一个数据集”,
线张力:0.5,
填充:是的,
背景颜色:渐变色,
边框颜色:“347aeb”,
风格:“屁股”,
borderDash:[],
边框宽度:5,
borderDashOffset:0.0,
边框样式:“圆形”,
pointBorderColor:#347AEB“,
pointBackgroundColor:“白色”,
点边界宽度:5,
点半径:5,
pointHoverBackgroundColor:“白色”,
pointHoverBorderColor:“rgba(2201)”,
pointHoverBorderWidth:2,
点半径:10,
点半径:10,
//展品系列:0,
数据:[65,59,80,81,56,55,40]
}
]
};
};
返回(
);
}