Рассмотрим каждый случай и построим графики линейных функций.
a) y = 2x
Для построения графика заполним таблицу значений:
<div style="overflow-x:auto;-webkit-overflow-scrolling:touch;width:100%;"><table style="white-space:nowrap;width:max-content;"><thead><tr><th>x</th><th>0</th><th>1</th></tr></thead><tbody><tr><td>y</td><td>0</td><td>2</td></tr></tbody></table></div>
<canvas id="myChart1" width="400" height="300"></canvas>
<script>
const ctx1 = document.getElementById('myChart1').getContext('2d');
const myChart1 = new Chart(ctx1, {
type: 'line',
data: {
labels: [-2, -1, 0, 1, 2],
datasets: [{
label: 'y = 2x',
data: [-4, -2, 0, 2, 4],
borderColor: 'blue',
borderWidth: 1,
pointRadius: 0
}]
},
options: {
scales: {
x: {
type: 'linear',
position: 'bottom'
},
y: {
type: 'linear',
position: 'left'
}
},
plugins: {
legend: {
display: true,
labels: {
color: 'rgb(0, 0, 0)'
}
}
}
}
});
</script>
б) y = -3x
Для построения графика заполним таблицу значений:
<div style="overflow-x:auto;-webkit-overflow-scrolling:touch;width:100%;"><table style="white-space:nowrap;width:max-content;"><thead><tr><th>x</th><th>0</th><th>1</th></tr></thead><tbody><tr><td>y</td><td>0</td><td>-3</td></tr></tbody></table></div>
<canvas id="myChart2" width="400" height="300"></canvas>
<script>
const ctx2 = document.getElementById('myChart2').getContext('2d');
const myChart2 = new Chart(ctx2, {
type: 'line',
data: {
labels: [-2, -1, 0, 1, 2],
datasets: [{
label: 'y = -3x',
data: [6, 3, 0, -3, -6],
borderColor: 'red',
borderWidth: 1,
pointRadius: 0
}]
},
options: {
scales: {
x: {
type: 'linear',
position: 'bottom'
},
y: {
type: 'linear',
position: 'left'
}
},
plugins: {
legend: {
display: true,
labels: {
color: 'rgb(0, 0, 0)'
}
}
}
}
});
</script>
в) y = x; y = -x
Для построения графика заполним таблицу значений:
<div style="overflow-x:auto;-webkit-overflow-scrolling:touch;width:100%;"><table style="white-space:nowrap;width:max-content;"><thead><tr><th>x</th><th>0</th><th>1</th></tr></thead><tbody><tr><td>y = x</td><td>0</td><td>1</td></tr><tr><td>y = -x</td><td>0</td><td>-1</td></tr></tbody></table></div>
<canvas id="myChart3" width="400" height="300"></canvas>
<script>
const ctx3 = document.getElementById('myChart3').getContext('2d');
const myChart3 = new Chart(ctx3, {
type: 'line',
data: {
labels: [-2, -1, 0, 1, 2],
datasets: [{
label: 'y = x',
data: [-2, -1, 0, 1, 2],
borderColor: 'green',
borderWidth: 1,
pointRadius: 0
}, {
label: 'y = -x',
data: [2, 1, 0, -1, -2],
borderColor: 'purple',
borderWidth: 1,
pointRadius: 0
}]
},
options: {
scales: {
x: {
type: 'linear',
position: 'bottom'
},
y: {
type: 'linear',
position: 'left'
}
},
plugins: {
legend: {
display: true,
labels: {
color: 'rgb(0, 0, 0)'
}
}
}
}
});
</script>