1

私には、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();
}

ご想像のとおり、出力はテーブルですが、私のグラフは空です。これを実現するために、最初に示したコードであるxhtmlマークアップの.aspxファイルでどのように動作できますか?

テンプレートフィールドにデータバインディング式を配置するのは難しいと思いますが、そこに何を配置すればよいかわかりません。

私を手伝ってくれますか?

ありがとうございました

PS:ここでは解決策を提供しなかったことに注意してください。問題は、データをグラフに接続する方法がわからないことです。実際には、グラフ(テーブル行ごとに1つ)に何も表示されないのは正しいことです。 aspxページでバインディング式を指定したり、コードビハインドで適切なコードを指定したりしないでください。

4

1 に答える 1

3

XHTMLでデータをチャートシリーズに直接バインドする便利な方法があるかどうかわかりませんか?しかし、GridView.RowDataBoundでイベントを作成し、そこでチャートコントロールを見つけて、データをチャートシリーズに追加することもできますか?

于 2011-06-13T09:08:01.463 に答える