score:80

Accepted answer

it is possible to either remove the grid lines or have them display in a different color.

in both options.scales.xaxes and options.scales.yaxes you can add

gridlines: {
  display: false ,
  color: "#ffffff"
},

(obviously you do not need to assign a colour if you are not disaplying them)

var chartcolors = {
  red: 'rgb(255, 99, 132)',
  orange: 'rgb(255, 159, 64)',
  yellow: 'rgb(255, 205, 86)',
  green: 'rgb(75, 192, 192)',
  blue: 'rgb(54, 162, 235)',
  purple: 'rgb(153, 102, 255)',
  grey: 'rgb(231,233,237)'
};

var randomscalingfactor = function() {
  return (math.random() > 0.5 ? 1.0 : -1.0) * math.round(math.random() * 100);
}
var months = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
var config = {
  type: 'line',
  data: {
    labels: ["january", "february", "march", "april", "may", "june", "july"],
    datasets: [{
      label: "my first dataset",
      backgroundcolor: chartcolors.red,
      bordercolor: chartcolors.red,
      data: [
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor()
      ],
      fill: false,
    }, {
      label: "my second dataset",
      fill: false,
      backgroundcolor: chartcolors.blue,
      bordercolor: chartcolors.blue,
      data: [
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor(),
        randomscalingfactor()
      ],
    }]
  },
  options: {
    responsive: true,
    title: {
      display: true,
      text: 'chart.js line chart'
    },
    tooltips: {
      mode: 'label',
    },
    hover: {
      mode: 'nearest',
      intersect: true
    },
    scales: {
      xaxes: [{
        display: true,
        gridlines: {
          display: false
        },
        scalelabel: {
          display: true,
          labelstring: 'month'
        }
      }],
      yaxes: [{
        display: true,
        gridlines: {
          display: false
        },
        scalelabel: {
          display: true,
          labelstring: 'value'
        }
      }]
    }
  }
};


var ctx = document.getelementbyid("canvas").getcontext("2d");
window.myline = new chart(ctx, config);
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.2.1/chart.js"></script>
<div style="width:100%;">
  <canvas id="canvas"></canvas>
</div>

score:-1

try this:

options: {
  scales: {
    x: {
      display: true,
      grid: {
        display: false
      },
    },
    y: {
      display: true,
      grid: {
        display: false
      },
    }
  }
}

score:6

since v3 the scales have been changed so if you want your gridlines to have a different color you will need to configure it in options.scales[scaleid].grid.color:

var options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12, 19, 3, 5, 2, 3],
        bordercolor: 'pink'
      },
      {
        label: '# of points',
        data: [7, 11, 5, 8, 3, 7],
        bordercolor: 'orange'
      }
    ]
  },
  options: {
    scales: {
      y: {
        grid: {
          color: 'white'
        }
      },
      x: {
        grid: {
          color: 'red'
        }
      }
    }
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.6.0/chart.js"></script>
</body>


Related Query

More Query from same tag