我是c#的新手。我想显示数据库中的数据看起来像图表然后我尝试使用Higchart.Js,但问题是当完成一个过程,它没有显示任何关于图表。
这是出局
这是我在View.aspx中的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="fuck.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/Highcharts-3.0.1/js/highcharts.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/Main.css" rel="stylesheet" />
<script src="Scripts/jquery-1.7.1.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
</head>
<body>
<form id="Form1" class="form-inline" runat="server">
<div class="form-group">
<asp:label id="myLabel" runat="server" />
<asp:Button ID="btnLogout" CssClass="btn" runat="server" Text="Logout" OnClick="btnLogout_Click" />
</div>
<div class="container">
<div class="legend">
<h3>Create charts</h3>
</div>
<table border="0">
<tr>
<td>
<asp:ListBox ID="ListDepartmentAll" SelectionMode="Multiple" runat="server" Width="180"></asp:ListBox>
</td>
<td>
<asp:Button id="btn_add" runat="server" Text=">>" CssClass="btn" OnClick="btn_add_Click" />
<asp:Button id="btn_remove" runat="server" Text="<<" CssClass="btn" OnClick="btn_remove_Click" />
</td>
<td>
<asp:ListBox ID="ListDepartmentSelect" SelectionMode="Multiple" runat="server" Width="180"></asp:ListBox>
</td>
<td>
<asp:ListBox ID="option_plot" SelectionMode="Single" runat="server" Width="180">
<asp:ListItem Value="Per Month"></asp:ListItem>
<asp:ListItem Value="Per Quoter"></asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button ID="btn_plot" runat="server" Text="Plot Grap" CssClass="btn btn-success" OnClick="btn_plot_Click1" />
</td>
</tr>
</table>
</div>
<div>
<highcharts:ColumnChart runat="server" ID="hc_charts" />
</div>
</form>
</body>
</html>
这是我的controll.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Highcharts.Core;
using Highcharts.Core.Data.Chart;
namespace fuck
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection sqlCon = new SqlConnection(@"Data Source=supertong-pc\sqlexpress;Initial Catalog=TestProject;Integrated Security=True");
List<String> title = new List<string>();
List<String> title_name = new List<string>();
//value if title have 1
List<Double> value_type1 = new List<double>();
List<Double> value_type2 = new List<double>();
List<Double> value_type3 = new List<double>();
List<Double> value = new List<double>();
SqlDataReader data_read;
string option;
int title_id;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
//get user name from Session
myLabel.Text = (String)Session["UserName"];
String dpm = (String)Session["DPM"];
if (Session["UserName"] == null)
{
Response.Redirect("~/test.aspx");
}
else
{
try
{
sqlCon.Open();
SqlCommand cmd = new SqlCommand("select title from titlevalue where dpm = '" + dpm + "'", sqlCon);
//use data read to read sqlcommand query
data_read = cmd.ExecuteReader();
while (data_read.Read())
{
//add title item to listbox ListDepartmentAll
ListDepartmentAll.Items.Add(Convert.ToString(data_read["title"]));
}
data_read.Close();
sqlCon.Close();
}
catch (Exception ex)
{
Response.Write("Error exception ::" + ex.Message.ToString());
}
//load title value in sql to fetch in list box
}
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
//clear session
Session.Abandon();
Response.Redirect("~/LoginForm.aspx");
}
protected void btn_add_Click(object sender, EventArgs e)
{
//add
foreach (ListItem li in ListDepartmentAll.Items)
{
if (li.Selected == true)
{
ListDepartmentSelect.Items.Add(li);
}
}
//remove
foreach (ListItem li in ListDepartmentSelect.Items)
{
ListDepartmentAll.Items.Remove(li);
}
}
protected void btn_remove_Click(object sender, EventArgs e)
{
//add
foreach (ListItem li in ListDepartmentSelect.Items)
{
if (li.Selected == true)
{
ListDepartmentAll.Items.Add(li);
}
}
//remove
foreach (ListItem li in ListDepartmentAll.Items)
{
ListDepartmentSelect.Items.Remove(li);
}
}
protected void btn_plot_Click1(object sender, EventArgs e)
{
int num = ListDepartmentSelect.Items.Count;
if (num != 0) {
//check option plot
option = Convert.ToString(option_plot.SelectedItem.ToString());
if (option == "Per Month") {
// how many item in ListdepartmentSelecte
if (num == 1) {
foreach (ListItem item in ListDepartmentSelect.Items)
{
try
{
sqlCon.Open();
SqlCommand get_titleID = new SqlCommand("select id from titlevalue where title ='" + item.Value.ToString() + "'", sqlCon);
data_read = get_titleID.ExecuteReader();
while (data_read.Read())
{
title_id = Convert.ToInt32(data_read["id"]);
}
data_read.Close();
//get value_type1
SqlCommand getValue1 = new SqlCommand("select sum(value) AS value from value where title_id ='" + title_id + "' AND cr_date >= '2005/12/01' AND cr_date <= '2006/02/28' GROUP BY MONTH(cr_date)", sqlCon);
data_read = getValue1.ExecuteReader();
while (data_read.Read())
{
value_type1.Add(Convert.ToDouble(data_read["value"]));
Response.Write(Convert.ToDouble(data_read["value"]) + "\n");
}
data_read.Close();
//get value_type2
SqlCommand getValue2 = new SqlCommand("select sum(value) AS value from value where title_id ='" + title_id + "' AND cr_date >= '2006/01/01' AND cr_date <= '2006/03/30' GROUP BY MONTH(cr_date)", sqlCon);
data_read = getValue2.ExecuteReader();
while (data_read.Read())
{
value_type2.Add(Convert.ToDouble(data_read["value"]));
Response.Write(Convert.ToDouble(data_read["value"]) + "\n");
}
data_read.Close();
//get value_type3
SqlCommand getValue3 = new SqlCommand("select sum(value) AS value from value where title_id ='" + title_id + "' AND cr_date >= '2005/01/01' AND cr_date <= '2005/03/30' GROUP BY MONTH(cr_date)", sqlCon);
data_read = getValue3.ExecuteReader();
while (data_read.Read())
{
value_type3.Add(Convert.ToDouble(data_read["value"]));
Response.Write(Convert.ToDouble(data_read["value"]) + "\n");
}
data_read.Close();
sqlCon.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
//Plot chart
hc_charts.Title = new Title("Performance Chart");
hc_charts.SubTitle = new SubTitle("Evaluate Chart");
hc_charts.XAxis.Add(new XAxisItem { categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } });
//set series
var test_series = new List<Serie>();
test_series.Add(new Serie { data = new object[] { 58.3, 76.2, 500, 88.2, 150.3, 60.6, 49.7, 58.9, 120.2, 80.3 }, name = "year1991", yAxis = 0 });
test_series.Add(new Serie { data = value_type1.Cast<object>().ToArray() });
test_series.Add(new Serie { data = value_type2.Cast<object>().ToArray() });
test_series.Add(new Serie { data = value_type3.Cast<object>().ToArray() });
//assign series to data source
hc_charts.DataSource = test_series;
hc_charts.DataBind();
}
}
}
}
}
}
我在列表中检查了它已经有价值的值。为什么它没有显示任何内容。请告诉我为什么以及如何做。谢谢
这是错误