Reputation: 9502
I have the following code to draw a line, but it won't draw. I only see the canvas border. I don't see any errors in the console.
index.html:
<div id="chart_area">
<canvas id="chart1" width="800" height="600"></canvas>
</div>
...
<script>
processChart()
</script>
style.css:
#chart_area
{
text-align:center;
color:red;
}
#chart1
{
text-align:center;
border:solid;
color:blue;
}
#control_panel
{
text-align:center;
color:red;
float:right;
clear:both;
}
chart.js:
function processChart() {
var b_canvas = document.getElementById("chart1");
var b_context = b_canvas.getContext("2d");
b_context.moveTo([0,0]);
b_context.lineTo([300,300]);
b_context.stroke()
}
Upvotes: 2
Views: 1521
Reputation: 3579
You should remove your '[' try this:
b_canvas = document.getElementById("chart1");
var b_context = b_canvas.getContext("2d");
b_context.moveTo(11,0);
b_context.lineTo(200,300);
b_context.stroke();
Upvotes: 1
Reputation: 2556
Those functions take two arguments, not an array. Also be sure to call beginPath prior to drawing paths, you'll get confused later if you dont :) Your code should be
b_context.beginPath();
b_context.moveTo(0, 0);
b_context.lineTo(300, 300);
b_context.stroke()
Some canvas tutorials:
Upvotes: 2