我有一个GridView
控件,我需要显示一些关于我的一些重要变量的信息。这些变量随时间变化,我想在表格中使用Chart
控件将它们的趋势绘制为最后一列。
这是代码的通用视图:
<asp:GridView runat="server" ID="Variables_GridView" CssClass="grid" AutoGenerateColumns="false" Width="100%">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle CssClass="gridheader" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
<Columns>
<asp:BoundField DataField="VariableName" HeaderText="Name" />
<asp:BoundField DataField="VariableType" HeaderText="Type" />
<asp:BoundField DataField="VariableDescription" HeaderText="Description" />
<asp:TemplateField HeaderText="Latest values">
<ItemTemplate>
<asp:Chart ID="Values_Chart" runat="server" Width="150" Height="50">
<Series>
<asp:Series Name="Values_Series" XAxisType="Primary" XValueType="Int32" ChartType="Line"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="Values_ChartArea"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
在我的代码隐藏中,您可以找到这种类型,用于映射属性(我指定的那些):
public class VariableRepresentation {
private string variableName;
private string variableType;
private string variableDescription;
private float[] variableValues;
public string VariableName {
get { return this.variableName; }
set { this.variableName = value; }
}
public string VariableType {
get { return this.variableType; }
set { this.variableType = value; }
}
public string VariableDescription {
get { return this.variableDescription; }
set { this.variableDescription = value; }
}
public float[] VariableValues {
get { return this.variableValues; }
set { this.variableValues = value; }
}
public VariableRepresentation(string name, string type, string description) {
this.variableName = name;
this.variableType = type;
this.variableDescription = description;
}
public VariableRepresentation(string name, string type, string description, float[] initialValues) : this(name, type, description) {
this.variableValues = initialValues;
}
}
好的!
在此页面的加载方法中,我有以下内容:
protected void Page_Load(object sender, EventArgs e) {
VariableRepresentation[] vars = new VariableRepresentation[6];
vars[0] = new VariableRepresentation("Variable 1",
"Type 1", "A generic variable", new float[] { 11, 12, 13, 14, 11, 20 });
vars[1] = new VariableRepresentation("Variable 2",
"Type 2", "A generic variable", new float[] { 11, 12, 13, 14, 11, 20 });
vars[2] = new VariableRepresentation("Variable 3",
"Type 3", "A generic variable", new float[] { 11, 12, 13, 14, 11, 20 });
vars[3] = new VariableRepresentation("Variable 4",
"Type 1", "A generic variable", new float[] { 11, 12, 13, 14, 11, 20 });
vars[4] = new VariableRepresentation("Variable 5",
"Type 2", "A generic variable", new float[] { 11, 12, 13, 14, 11, 20 });
vars[5] = new VariableRepresentation("Variable 6",
"Type 3", "A generic variable", new float[] { 11, 12, 13, 14, 11, 20 });
this.Variables_GridView.DataSource = vars;
this.Variables_GridView.DataBind();
}
好吧,您可以想象,输出是一个表格,但我的图表是空的。我如何在 .aspx 文件、xhtml 标记、我展示的第一个代码中采取行动,让这种情况发生?
我想我应该在模板字段中放置一些数据绑定表达式,但我不知道该放置什么......
请问你能帮帮我吗?
谢谢
PS:请注意,这里我没有提供解决方案,问题是我不知道如何将数据连接到图表,实际上图表(每表行一个)什么都不显示是正确的,因为我做了没有在 aspx 页面中指定任何绑定表达式,也没有在代码隐藏中指定一段正确的代码。