Using the DataVisualization.Charting.Chart control, I need to create a bar chart (maybe stacked bar chart) that shows per person the number of hours booked for that person and a those hours' percentage of total hours. So far I am a bit overwhelmed by the number of collections and properties to set on this beast, so I'd appreciate some help on first getting my chart up, then I'll explore more on my own.
I need to bind the chart to a list of the following object:
Public Class DOHoursChartItem
Public Property Name As String
Public Property Hours As Double
Public Property Percent As Double
End Class
I'm not sure I need the percentage property here, in favour of somehow letting the chart control handle this and just give it the Hours
value per point and a total hours value, but that's why I'm asking: how do I set up the chart I describe above?
I'm not very good in VB, so I will start posting an example in C# (then I can try to translate it if you really need).
Here are three examples of methods that you can use to bind your items to a mschart and get columns charts:
Example 1: single area and side-by-side columns
Example 2: two charts one upon the other
Example 3: single area and stacked columns
Where
GetItems
method is defined as follows (for all the examples):and
DOHoursChartItem
as :N.B.
these are actually Column charts; by setting the ChartType to
Bar
(orStackedBar
), you will get the same result but the bars will have an horizontal orientation.