Jump to content
Software FX Community

Aggregating values of one column by the values of another for a bar chart


Recommended Posts

I have a list of objects, named EmailCampaign, as the datasource of a bar chart. The objects include two properties: EmailsSent (int), and ContentType (string). The value of the ContentType property can be "Newsletter", "Concept Piece", and others. What I want the bar chart to show is the aggregates of all the EmailsSent property values, with a different bar for each distinct value of the ContentType property. How can I accomplish this?




Link to comment
Share on other sites

Here is some sample data to show what I'm trying to accomplish:

class EmailCampaign{    private int emailsSent;    public int EmailsSent    {	    get { return emailsSent; }    }    private string contentType;    public string ContentType    {	    get { return contentType; }    }    public EmailCampaign(int emailsSent, string contentType)    {	    this.emailsSent = emailsSent;	    this.contentType = contentType;    }}

EmailCampaign[] emailCampaigns = new EmailCampaign[4];emailCampaigns[0] = new EmailCampaign(1, "Concept Piece");emailCampaigns[1] = new EmailCampaign(3, "Newsletter");emailCampaigns[2] = new EmailCampaign(4, "Newsletter");emailCampaigns[3] = new EmailCampaign(4, "Concept Piece");

As you can see, summing the values of the EmailsSent property for all the EmailCampaign instances where the value of the ContentType property is "Concept Piece" totals 5, and where the value is "Newsletter" totals 7. What I want to do somehow is to create a bar chart using the emailCampaigns array as a datasource that would in this case have one bar, labeled "Concept Piece," with a height of 5, and another bar, labeled "Newsletter" with a height of 7.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...