0

我设计了一个表格,并使用表格上的条形图来显示在特定年份(例如 2009 年)在特定项目(护理)中遇到特定问题(例如家庭问题)的学生人数。我设计了其他所有东西来从数据库中获取总数并将其显示在条形图上。我可以在表单上实现这一点,但我必须生成报告并在报告上显示相同的条形图。我的问题是我可以在不连接数据库的情况下实现这一点吗?如果是,那么太棒了,但是如何?提前致谢。

下面的代码是 3 年内在特定项目中有问题(家庭问题、吸毒者等)的学生总数的条形图代码。

    public void calculateStatsFor3Years(int year1, int year2, int year3)
    {
         //count the number of students in with intervention in particular program in a year

        intervention.Classes.Programs objPrograms = new intervention.Classes.Programs();

        List<int> programCodeList = objPrograms.GetProgramCode();

        List<int> numStudentsYear1 = new List<int>();
        List<int> numStudentsYear2 = new List<int>();
        List<int> numStudentsYear3 = new List<int>();

        int temp1 = 0;
        int temp2 = 0;
        int temp3 = 0;

        for (int counter = 0; counter < programCodeList.Count; counter++)
        {

            temp1 = Convert.ToInt32(objControllerClass.get_students_intervention_particular_year_program(year1, programCodeList.ElementAt(counter)));

            numStudentsYear1.Add(temp1);

            temp2 = Convert.ToInt32(objControllerClass.get_students_intervention_particular_year_program(year2, programCodeList.ElementAt(counter)));

            numStudentsYear2.Add(temp2);

            temp3 = Convert.ToInt32(objControllerClass.get_students_intervention_particular_year_program(year3, programCodeList.ElementAt(counter)));

            numStudentsYear3.Add(temp3);

        }//for 

        int[] yValues0 = numStudentsYear1.ToArray();//2011-2012
        int[] yValues1 = numStudentsYear2.ToArray();//2010-2011
        int[] yValues2 = numStudentsYear3.ToArray();//2009-2010 


        string[] xNameSeries0 = { "Agent immobilier", "Mécanique du bâtiment", "Gestion des eaus ", "Soins infirmiers ", "Anglais ", "Comtabilité et gestion ", "Bureautique ", "Architecture et gestion de réseau ", "Programmeur web ", "Assurance de dommages ", "O'Bois ", "Éducation à l'enface ", "Francisation " };

        myBarChart.Series[0].Points.DataBindXY(xNameSeries0, yValues0);
        myBarChart.Series[1].Points.DataBindXY(xNameSeries0, yValues1);
        myBarChart.Series[2].Points.DataBindXY(xNameSeries0, yValues2);


        //legend text
        myBarChart.Series[0].LegendText = year1.ToString();
        myBarChart.Series[1].LegendText = year2.ToString();
        myBarChart.Series[2].LegendText = year3.ToString();

    }//calculateStatsFor3Years()

这是我需要在 Crystal Reports 中显示的水平图的屏幕截图。

http://i1342.photobucket.com/albums/o765/CSharpJunior/C%20Sharp%20project/horizo​​ntalGraph.jpg

4

1 回答 1

0

这个有可能。最好的方法可能是使用数据集。我经常提到人们:http ://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-without-database.htm

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet1 ds = new DataSet1();
            DataTable t = ds.Tables.Add("Items");
            t.Columns.Add("id", Type.GetType("System.Int32"));
            t.Columns.Add("Item", Type.GetType("System.String"));

            DataRow r ;
            int i = 0;
            for (i = 0; i <= 9; i++)
            {
                r = t.NewRow();
                r["id"] = i;
                r["Item"] = "Item" + i;
                t.Rows.Add(r);
            }

            CrystalReport1 objRpt = new CrystalReport1();
            objRpt.SetDataSource(ds.Tables[1]);
            crystalReportViewer1.ReportSource = objRpt;
            crystalReportViewer1.Refresh(); 
        }
    }
}
于 2012-11-17T09:31:36.013 回答