.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
None
0 Points
2 Posts
c# chart.js webform help
Jul 15, 2019 05:40 PM|infotba|LINK
Hi
my default.aspx.cs code :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="ChartDene._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://cdnjs.com/libraries/Chart.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<canvas id="myChart" width="400" height="400"></canvas>
</form>
</body>
</html>
and
defaul.aspx is
protected void Page_Load(object sender, EventArgs e)
{
string chart = "";
chart += "<script>";
chart += "var ctx = document.getElementById('myChart').getContext('2d');";
chart += "var myChart = new Chart(ctx, {";
chart += " type: 'bar',";
chart += " data:";
chart += " {";
chart += " labels: ['Red', 'Blue'],";
chart += " datasets: [{";
chart += " data: [110, 2000]";
chart += " }]";
chart += " },";
chart += " });";
chart += "</script>";
}
Chart is not displaying
please help me,
All-Star
53121 Points
23672 Posts
Re: c# chart.js webform help
Jul 15, 2019 05:44 PM|mgebhard|LINK
See the following.
https://forums.asp.net/p/2129509/6169081.aspx
Contributor
3370 Points
1409 Posts
Re: c# chart.js webform help
Jul 16, 2019 03:26 AM|samwu|LINK
Hi infotba,
When you put the script into code behind, you should use RegisterStartupScript method to Registers the startup script with the Page object.
More information about RegisterStartupScript you can reference this link: https://forums.asp.net/t/2157780.aspx
Note: The code I tested is my own chart.js
The code:
The result:
Best regards,
Sam
Participant
1253 Points
936 Posts
Re: c# chart.js webform help
Jul 16, 2019 05:45 AM|yogyogi|LINK
You are just starting with Chart.js. This is covered really well in this thread:
help : populate chart
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠