[英]ASP.net AjaxToolKit LineChart Drawing Series
I have the following SqlServer Data Table :我有以下 SqlServer 数据表:
Years |年 | Sales(A) |销售(A) | Sales(B)销售(B)
------------------------------ ------------------------------
2000 | 2000 | 38000 | 38000 | 55000 55000
2001 | 2001 | 18000 | 18000 | 47000 47000
2002 | 2002 | 70000 | 70000 | 16000 16000
2003 | 2003 | 21000 | 21000 | 55000 55000
2004 | 2004 | 77000 | 77000 | 50000 50000
2005 | 2005 | 16000 | 16000 | 64000 64000
2006 | 2006 | 82000 | 82000 | 61000 61000
2007 | 2007 | 37000 | 37000 | 16000 16000
and I need to compare these to columns by using AjaxToolKit LineChart in ASP Page I have the following :我需要通过在 ASP 页面中使用 AjaxToolKit LineChart 将这些与列进行比较我有以下内容:
** **
ASPX ASPX
** **
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div style="width: 100%; height: 50px">
<h1>Ajax Database Multiline Chart Tutorial </h1>
</div>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Generate Chart" />
<br />
<br />
<div style="width: 100%; height: 500px">
<ajaxToolkit:LineChart ID="LineChart1" runat="server" ChartType="Stacked" ChartWidth="720" Width="800px" ChartTitle="Arabian Food Supplies Annual Sales">
</ajaxToolkit:LineChart>
</div>
</asp:Content>
** **
VB Code VB代码
** **
Imports System.Data.SqlClient
Public Class AjaxLineChartDatabase
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Compare(sender As Object, e As EventArgs) Handles Button1.Click
Dim dt As DataTable = GetData("SELECT Years,A FROM LineChart")
Dim x As String() = New String(dt.Rows.Count - 1) {}
Dim y As Decimal() = New Decimal(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
x(i) = dt.Rows(i)(0).ToString()
y(i) = Convert.ToInt32(dt.Rows(i)(1))
Next
LineChart1.Series.Add(New AjaxControlToolkit.LineChartSeries() With {
.Name = "Series 1",
.Data = y
})
dt = GetData("SELECT Years,B FROM LineChart")
y = New Decimal(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
x(i) = dt.Rows(i)(0).ToString()
y(i) = Convert.ToInt32(dt.Rows(i)(1))
Next
LineChart1.Series.Add(New AjaxControlToolkit.LineChartSeries() With {
.Name = "Series 2",
.Data = y
})
LineChart1.CategoriesAxis = String.Join(",", x)
LineChart1.ChartTitle = String.Format("{0} and {1} Distribution", "S-1", "S-2")
LineChart1.Visible = True
End Sub
Private Shared Function GetData(query As String) As DataTable
Dim dt As New DataTable()
Dim constr As String = ConfigurationManager.ConnectionStrings("ChartsConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(query)
Using sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
sda.SelectCommand = cmd
sda.Fill(dt)
End Using
End Using
Return dt
End Using
End Function
End Class
The problem when I draw the chart, the first series(A) appears OK but the 2nd Series(B) values appear as A+B绘制图表时出现的问题,第一个系列(A)显示正常,但第二个系列(B)值显示为 A+B
My theory, is the array is just getting appended.我的理论是数组刚刚被追加。 *Note, we may need separate arrays as it's getting rendered after the code. *注意,我们可能需要单独的数组,因为它是在代码之后呈现的。
Try this,尝试这个,
dt = GetData("SELECT Years,A, B FROM LineChart")
y = New Decimal(dt.Rows.Count - 1) {}
y2 = New Decimal(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
x(i) = dt.Rows(i)(0).ToString()
y(i) = Convert.ToInt32(dt.Rows(i)(1))
y2(i) = Convert.ToInt32(dt.Rows(i)(2))
Next
LineChart1.Series.Add(New AjaxControlToolkit.LineChartSeries() With {
.Name = "Series 2",
.Data = y
})
LineChart1.Series.Add(New AjaxControlToolkit.LineChartSeries() With {
.Name = "Series 2",
.Data = y2
})
LineChart1.CategoriesAxis = String.Join(",", x)
LineChart1.ChartTitle = String.Format("{0} and {1} Distribution", "S-1", "S-2")
LineChart1.Visible = True
I have solved the issue : it's coming from ChartType Property.我已经解决了这个问题:它来自ChartType属性。
Problem:问题:
<div style="width: 100%; height: 500px">
<ajaxToolkit:LineChart ID="LineChart1" runat="server" ChartType="Stacked" ChartWidth="720" Width="800px" ChartTitle="Sales">
</ajaxToolkit:LineChart>
Solution :解决方案 :
<div style="width: 100%; height: 500px">
<ajaxToolkit:LineChart ID="LineChart1" runat="server" ChartType="Basic" ChartWidth="720" Width="800px" ChartTitle="Sales">
</ajaxToolkit:LineChart>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.