質問

私は持っています 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>

私のCodeBehindでは、このタイプを見つけることができます。このタイプは、プロパティのマッピングに使用されているもの(指定したものです):

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ページでバインディング式を指定したり、CodeBehindに適切にコードを指定したりしないでください。

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top