Interpolation Modes

Interpolation Modes - 图1

config setup

  1. const config = {
  2. type: 'line',
  3. data: data,
  4. options: {
  5. responsive: true,
  6. plugins: {
  7. title: {
  8. display: true,
  9. text: 'Chart.js Line Chart - Cubic interpolation mode'
  10. },
  11. },
  12. interaction: {
  13. intersect: false,
  14. },
  15. scales: {
  16. x: {
  17. display: true,
  18. title: {
  19. display: true
  20. }
  21. },
  22. y: {
  23. display: true,
  24. title: {
  25. display: true,
  26. text: 'Value'
  27. },
  28. suggestedMin: -10,
  29. suggestedMax: 200
  30. }
  31. }
  32. },
  33. };
  1. const DATA_COUNT = 12;
  2. const labels = [];
  3. for (let i = 0; i < DATA_COUNT; ++i) {
  4. labels.push(i.toString());
  5. }
  6. const datapoints = [0, 20, 20, 60, 60, 120, NaN, 180, 120, 125, 105, 110, 170];
  7. const data = {
  8. labels: labels,
  9. datasets: [
  10. {
  11. label: 'Cubic interpolation (monotone)',
  12. data: datapoints,
  13. borderColor: Utils.CHART_COLORS.red,
  14. fill: false,
  15. cubicInterpolationMode: 'monotone',
  16. tension: 0.4
  17. }, {
  18. label: 'Cubic interpolation',
  19. data: datapoints,
  20. borderColor: Utils.CHART_COLORS.blue,
  21. fill: false,
  22. tension: 0.4
  23. }, {
  24. label: 'Linear interpolation (default)',
  25. data: datapoints,
  26. borderColor: Utils.CHART_COLORS.green,
  27. fill: false
  28. }
  29. ]
  30. };