我想用js创建一个图表。我从Label获取标签行x的值
通过从sql选择数据并获取条件,但是当我设置labels = Label
时,图表不会显示。
请帮助我,我尝试了所有建议。
lbldate.Text = lbldate.Text + D1 +“,” + D2 +“,” + D3 +“,” + D4 +“,”;
<script type="text/javascript">
var ldate = $('[id*=lbldate]').val();
var config = {
type: 'line',
data: {
labels: ldate,
datasets: [{
label: "My First dataset",
data: [65, 40, 80, 81, 56, 85, 45],
backgroundColor: "rgba(255,99,132,0.2)",
}, {
label: "My Second dataset",
data: [40, 80, 21, 56, 85, 45, 65],
backgroundColor: "rgba(99,255,132,0.2)",
}]
},
scales: {
xAxes: [{
gridLines: {
display: false,
lineWidth: 1,
zeroLineWidth: 1,
zeroLineColor: '#666666',
drawTicks: false
},
ticks: {
display: true,
stepSize: 0,
min: 0,
autoSkip: false,
fontSize: 11,
padding: 12
}
}],
yAxes: [{
ticks: {
padding: 5
},
gridLines: {
display: true,
lineWidth: 1,
zeroLineWidth: 2,
zeroLineColor: '#666666'
}
}]
},
spanGaps: true,
responsive: true,
maintainAspectRatio: true
};
var ctx = document.getElementById("myChart").getContext("2d");
new Chart(ctx, config);
</script>
<asp:Label ID="lbldate" runat="server" Text=""></asp:Label>
<div class="myChart">
<canvas id="myChart"></canvas>
</div>
答案 0 :(得分:0)
检查创建新图表https://www.chartjs.org/docs/latest/developers/charts.html,您缺少选项,结构应类似于:
new Chart(ctx, {
type: 'MyType',
data: data,
options: options
});
接下来的事情是,您发送到图表的标签应该位于数组中,不能像labels: something
那样写成labels: [something]
,因为它试图映射带有标签的数组,而您不会没有数组,则重现错误。