How To: Create a Dynamic Stacked Bar Chart
Any reporting tool cannot be called complete without a charting feature. ActiveReports 7 being a very robust reporting tool provides a nice support for different types of charts. In one of the blog posts, I discussed about creating a dynamic Pie Chart and in this blog post I would be discussing about creating a Stacked Bar chart at run time. A Stacked bar chart is a graph that is used to compare the parts to the whole. The bars in a stacked bar graph are divided into categories. Each bar represents a total. Before we start with the implementation, let us see how our final chart will look like:In this chart each series represent a bar plotted onto the chart and the series type has been set to StackedBar. The first thing which is required to plot the chart is a datasource which will provide data to the chart. Since we are creating the chart at runtime, we will use the ReportStart event to assign the datasource.
When creating a chart there are different properties which needs to be set in order to get the desired results. For example in this blog, in addition to the bars, I have also added markers to the bars so that they become more informative. The Grid Lines, Legend customization etc are all part of different changes which we can apply to the chart. Since the chart control has been placed in the Detail section of the report we will use the Detail_Format event to write the code. Let us see how the code looks like:
Sample applications demonstrating the above functionality can be downloaded in both VB.NET and C# from the following links: Stacked_Bar_C# Stacked_Bar_VB.NET