'System.Double'形式为'System.Collections.IEnumerable' [英] 'System.Double' form to 'System.Collections.IEnumerable'
问题描述
我正在尝试绘制圆半径1.
我想将原始圆数据存储在IEnumeration中,以便我可以绘制它。
我使用的是ASP.net 4.0
我需要帮助将数据从'System.Double'格式更改为'插入我的图表的System.Collections.IEnumerable'表单。这是我的代码:
I am trying to graph a circle radius 1.
I want to store the raw circle data in an IEnumeration so I can graph it.
I am using ASP.net 4.0
I need help changing the data from 'System.Double' form to 'System.Collections.IEnumerable' form to plug into my graph. Here is my code:
<asp:Chart ID="Chart1" runat="server">
<Series>
<asp:Series Name="Series1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x, y
For t = 0 To 2 * 3.2 Step 0.1
x = Math.Cos(t)
y = Math.Sin(t)
'change x and y to IEnumerable form xe and ye
Chart1.Series("Series1").Points.DataBindXY(xe, ye)
Chart1.Series("Series1").IsVisibleInLegend = True
Chart1.Series("Series1").IsValueShownAsLabel = True
Chart1.Series("Series1").Color = System.Drawing.Color.Red
Next t
End Sub
推荐答案
简单,只需创建一个包含一个元素的数组并将其传入。元素是你的双倍le value。
在C#中它:
double [] myDouble = new double [1] { 10.0};
不是VB人,但你明白了。
< br $> b $ b
让我改进:
Simple, just create an array with one element and pass that in. The single element is your double value.
In C# its:
double[] myDouble = new double[1] { 10.0 };
Not a VB guy, but you get the idea.
Let me improve:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x, y
Dim xe as List(of double)
Dim ye as List(of double)
For t = 0 To 2 * 3.2 Step 0.1
x = Math.Cos(t)
y = Math.Sin(t)
'change x and y to IEnumerable form xe and ye
xe.Add(x)
ye.Add(y)
Next t
Chart1.Series("Series1").Points.DataBindXY(xe, ye)
Chart1.Series("Series1").IsVisibleInLegend = True
Chart1.Series("Series1").IsValueShownAsLabel = True
Chart1.Series("Series1").Color = System.Drawing.Color.Red
End Sub
没有理由一遍又一遍地设置相同的属性,你可以在for循环之外做一次。 IEnumerable适用于数组和列表,任何可以枚举的东西。我不确定我是否正确定义了列表,但我认为你应该能够修复它。
There is no reason to set the same properties over and over again, you can do it once outside the "for" loop. IEnumerable works for arrays and lists, anything really that is enumerable. I'm not sure I defined the list correctly but I think you should be able to fix it.
这篇关于'System.Double'形式为'System.Collections.IEnumerable'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!