在图表中动态创建系列

时间:2013-02-22 10:28:49

标签: c# charts reportviewer

我需要在ReportViewer的图表中创建很多系列,但我只能创建固定数量的系列。
我怎样才能创建不固定的系列?

1 个答案:

答案 0 :(得分:0)

定义customdata classe

public class classData
{
    public String name { get; set; }

    public classData()
    {

    }
}

并从VS添加DataSource。

预备清单

List<classData> lst = new List<classData>();

从Datatable填充列表...

DataRow[] result = datatable.Select();
foreach (DataRow row in result)
{
   classDatat = new classData();
   t.name = row["name"].ToString();
   last.Add(t);
}

将数据传递给报告

ReportDataSource rds = new ReportDataSource("DataSet1_Customers_DataTable1", lst);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.RefreshReport();

报告rdl

 <DataSets>
    <DataSet Name="DataSet1_Customers_DataTable1">
      <Fields>
        <Field Name="NameFromReport">
          <DataField>name</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
    </DataSet>
 </DataSets>

并使用NameFromReport显示数据

<Textbox Name="textboxName">
    <rd:DefaultName>textbox1</rd:DefaultName>
    <Top>0.25cm</Top>
    <Width>8.75cm</Width>
    <Style>
      <FontFamily>Century Gothic</FontFamily>
      <FontSize>18pt</FontSize>
      <FontWeight>700</FontWeight>
      <PaddingLeft>2pt</PaddingLeft>
      <PaddingRight>2pt</PaddingRight>
      <PaddingTop>2pt</PaddingTop>
      <PaddingBottom>2pt</PaddingBottom>
    </Style>
    <ZIndex>1</ZIndex>
    <CanGrow>true</CanGrow>
    <Height>1.5cm</Height>
    <Value>=NameFromReport</Value>
</Textbox>

结束好工作!