[英]How to get line x value from Label chart js
I want to create a Chart in js. 我想在js中创建一个图表。 I get the value for labels line x from Label by selecting data from sql and get condition, but when I set
labels = Label
, the Chart does not show. 通过从sql中选择数据并获取条件,我从Label获得了标签行x的值,但是当我设置
labels = Label
,图表不显示。
Please help me, I tried to try every suggestion. 请帮助我,我尝试了所有建议。
lbldate.Text = lbldate.Text + D1 + "," + D2 + "," + D3 + "," + D4+","; 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>
Check creating new chart https://www.chartjs.org/docs/latest/developers/charts.html , you are missing options, structure should look like: 检查创建新图表https://www.chartjs.org/docs/latest/developers/charts.html ,您缺少选项,结构应类似于:
new Chart(ctx, {
type: 'MyType',
data: data,
options: options
});
Next thing is that labels what you send to chart should be in array, you can't write like labels: something
it should be labels: [something]
, because it's trying to map array with labels and you don't have array, then it reproduces error. 接下来的事情是,发送到图表的标签应该在数组中,不能像
labels: something
那样写labels: something
它应该是labels: [something]
,因为它试图用标签映射数组,而您没有数组,那么它重现错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.