0

This is the first time I'm trying to use the ASP.NET Chart control. I always used other third party charts.

This time, I'm creating a web form user control that uses the Chart control.

Let me start with my data. This is the data I have, that is being returned from a database function: enter image description here

I want my chart control to display data for October, November, and December. As you can see, November has 3 records - that is because the 'status' differs. So, I expect my chart control to have the following bars:

- 1 October X value with 1 bar 'lost' with Y count 2

- 1 November X value with 3 bars 'lost, stolen, found' with 1 Y count each.

- 1 December X Value with 1 bar 'stolen' with Y count 1

I'm getting a datatable with the above screenshot structure when the control loads, and then bind the chart like this:

        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = _stolenFunctions.GetDashboardChartDataTable(DateTime.Now.Year);

            StolenControlBarChart.DataBindCrossTable(dt.AsEnumerable(), "Status", "Month", "Count", "Label=Status");
        }

ASP.NET code:

    <asp:Chart ID="StolenControlBarChart" CssClass="stolenControlBarChart" Width="500" runat="server">
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
        </ChartAreas>
    </asp:Chart>

But for some reason, the data the chart displays looks like this: enter image description here

Can anyone please help me in the right direction here? :)

Fred
  • 2,402
  • 4
  • 31
  • 58

1 Answers1

1

Not sure this is going to be much help, but what does the graph look like if you add the other statuses that aren't showing with 0 counts. Does that make the graph look correct? I'm just wondering if each month is expecting 3 results and something is getting skewed from only receiving 1 result in the first month. Not that it's a solution but it might give you enough information to move forward.

In other words, try adding rows to the database to get this result back

MONTH    Status    Count
October  Lost      2
October  Stolen    0
October  Found     0
November Stolen    1
November Lost      1
November Found     1
December Stolen    1
December Lost      0
December Found     0

Does that make the chart properly?

Charles May
  • 1,725
  • 1
  • 11
  • 18
  • Yepp, you were right Charles, that was the problem. How the chart translated the data to look as weird as it did - I don't know, but all I needed to do was to update my SQL function to return 'zero' data for the months that don't have that I needed to display as you indicated :). Thanx! Problem solved! – Fred Dec 23 '15 at 11:30