How to define the layout of a data source?

advertisements

I have a C# program that needs to display a chart with 2 serie objects. Currently I just have a dataset with 2 datatables. The two tables have the same layout. I bind the dataset to the datasource property of the chart and execute the databind() method. It only displays one serie.

I think the solution lies in defining a custom bindingcontext, but I can't seem to figure it out. Can somebody please help me? Thanks.

Below is some of my code:

        DataSet dataSet = new DataSet();

        DataTable dataTable = database.Query("select sum(amount) as monthamount, month(transdate) as month from transaction where year(transdate)=" + balanceDateTimePicker.Value.Year + " group by month");
        dataSet.Tables.Add(dataTable);

        dataTable = database.Query("select sum(amount) as monthamount, month(transdate) as month from transaction where year(transdate)=" + balanceDateTimePicker.Value.AddYears(-1).Year + " group by month");
        dataSet.Tables.Add(dataTable);

        reoccuranceChart.DataSource = dataSet;
        System.Windows.Forms.DataVisualization.Charting.Series series = reoccuranceChart.Series["Series1"];
        series.XValueMember = "month";
        series.YValueMembers = "monthamount";
        series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
        series.IsVisibleInLegend = false;

        series = reoccuranceChart.Series["Series2"];
        series.XValueMember = "month";
        series.YValueMembers = "monthamount";
        series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
        series.IsVisibleInLegend = false;

        reoccuranceChart.DataBind();


I found it. It was actually fairly simple. All I had to do was, bind the series.points individually:

        DataSet dataSet = new DataSet();

        DataTable dataTable = database.Query("select sum(amount) as monthamount, month(transdate) as month from transaction where year(transdate)=" + balanceDateTimePicker.Value.Year + " group by month");
        dataSet.Tables.Add(dataTable);

        dataTable = database.Query("select sum(amount) as monthamount, month(transdate) as month from transaction where year(transdate)=" + balanceDateTimePicker.Value.AddYears(-1).Year + " group by month");
        dataSet.Tables.Add(dataTable);

        System.Windows.Forms.DataVisualization.Charting.Series series = reoccuranceChart.Series["Now"];
        series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
        //series.IsVisibleInLegend = false;
        series.Points.DataBind(dataSet.Tables[0].DefaultView, "month", "monthamount", "");

        series = reoccuranceChart.Series["Last year"];
        series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
        //series.IsVisibleInLegend = false;
        series.Points.DataBind(dataSet.Tables[1].DefaultView, "month", "monthamount", "");