{"id":334,"date":"2013-06-07T10:07:30","date_gmt":"2013-06-07T10:07:30","guid":{"rendered":"http:\/\/mindfusion.eu\/blog\/?p=334"},"modified":"2021-01-08T15:31:47","modified_gmt":"2021-01-08T15:31:47","slug":"working-hours-bar-chart-in-winforms","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/working-hours-bar-chart-in-winforms\/","title":{"rendered":"Working Hours Bar Chart in WinForms"},"content":{"rendered":"<p>In this post we will explore how to create a bar chart that shows the weekly working hours for each<br \/>\nmember of a team. We use MindFusion.Charting for WinForms component.<\/p>\n<p><strong>The Type of the Bar Chart<\/strong><\/p>\n<p>We decide to use a horizontal bar chart, which will give a clear visual representation of the data in this case. We use the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_BarChart_BarType_0.htm\">BarType<\/a> property to choose the bar type and set the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_AxesChart_Horizontal_0.htm\">Horizontal<\/a> property:<\/p>\n<p><code>barChart1.Horizontal = true;<br \/>\nbarChart1.BarType = MindFusion.Charting.BarType.Single3D;<\/code><\/p>\n<p>A 3D chart would look more sophisticated so we choose &#8220;Single3D&#8221; for a <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_BarChart_BarType_0.htm\">BarType<\/a>.<\/p>\n<p><strong>The Data<\/strong><\/p>\n<p>We don&#8217;t need to set data for both axes &#8211; one is enough. The control automatically sets values for the<br \/>\nother axis to make the bars equally distributed. We can write the data by hand or use the built-in<br \/>\ndesign time collection editor:<\/p>\n<p><code><br \/>\nbarChart1.Data.Add(new List() { 82, 60, 73, 45, 19, 34, 58, 23, 69, 17 });<\/code><\/p>\n<div id=\"attachment_336\" style=\"width: 258px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_collection_editor.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-336\" class=\"size-full wp-image-336\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_collection_editor.png\" alt=\"The data collection editor\" width=\"248\" height=\"309\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_collection_editor.png 248w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_collection_editor-240x300.png 240w\" sizes=\"auto, (max-width: 248px) 100vw, 248px\" \/><\/a><p id=\"caption-attachment-336\" class=\"wp-caption-text\">The data collection editor<\/p><\/div>\n<p><strong>The Axes<\/strong><\/p>\n<p>The X-axis shows a scale of the total working hours for the week. We set its <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_AxisSettings_AxisLabelType_0.htm\">LabelType<\/a> to &#8220;<a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?T_MindFusion_Charting_LabelType.htm\">AutoScale<\/a>&#8221;<br \/>\nand set the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_AxisSettings_AxisDelta_0.htm\">interval<\/a> to 10:<\/p>\n<p><code>barChart1.XAxisSettings.LabelType = MindFusion.Charting.AxisLabelType.AutoScale;<br \/>\nbarChart1.XAxisSettings.AxisDelta = 10;<\/code><\/p>\n<p>This is the only axis that shows numbers on the chart, so we show the starting zero number:<\/p>\n<p><code>barChart1.XAxisSettings.DrawZero = true;<\/code><\/p>\n<p>We want to show whole numbers at the axis &#8211; no decimal fractions &#8211; and we use the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?CC_P_MindFusion_Charting_AxisSettings_NumberFormat_0_0.htm\">NumberFormat<\/a> property to set this:<\/p>\n<p><code>barChart1.XAxisSettings.NumberFormat = MindFusion.Charting.NumberFormat.Fixed_point_0Digits;<\/code><\/p>\n<p>Finally, we set the title:<\/p>\n<p><code>barChart1.XAxisSettings.TitleLabel = \"Total Weekly Hours\";<\/code><\/p>\n<p>For the Y-axis we want to show custom labels &#8211; the name of each employee. We use the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_AxesChart_YLabels_0.htm\">YLabels<\/a> property to specify the labels and set <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_AxesChart_YAxisSettings_0.htm\">YAxisSettings.LabelType<\/a> to the appropriate value:<\/p>\n<p><code>barChart1.YAxisSettings.LabelType = MindFusion.Charting.AxisLabelType.CustomText;<br \/>\nbarChart1.YLabels.Add(new List() { \"Mary Johnson\", \"Tim Davidson\", \"Alan  Hank\", \"Elisa Labate\", \"Boris Foster\", \"Tim Carnes\", \"Olivia Beverling\", \"Mark Buchanan\", \"Ron Callary\", \"Cindy Peterson\" });<\/code><\/p>\n<p><strong>The Grid<\/strong><\/p>\n<p>A vertical grid will help us identify the value of each bar. The <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_AxesChart_GridType_0.htm\">GridType<\/a> property, together with the<br \/>\n<a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_AxesChart_GridBrush_0.htm\">GridBrush<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_AxesChart_AltGridBrush_0.htm\">AltGridBrush<\/a> help use set the type and colors of the grid. We outline the plot area with PlotAreaOutline:<\/p>\n<p><code>GridType = MindFusion.Charting.GridType.VertScale;<br \/>\nbarChart1.GridBrush = new MindFusion.Drawing.SolidBrush(Color.White);<br \/>\nbarChart1.AltGridBrush = new MindFusion.Drawing.SolidBrush(Color.FromArgb(240, 240, 240));<br \/>\nPlotAreaOutlinePen = new MindFusion.Drawing.Pen(Color.FromArgb(220, 220, 220));<\/code><\/p>\n<p><strong>The Bar Colors<\/strong><\/p>\n<p>We use <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_Chart_ChartBrushes_0.htm\">ChartBrushes<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_Chart_ChartPens_0.htm\">ChartPens<\/a> to specify how our bars will be colored. Here is the final chart:<\/p>\n<div id=\"attachment_340\" style=\"width: 518px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_bar_chart_marketing_team.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-340\" class=\"size-full wp-image-340\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_bar_chart_marketing_team.png\" alt=\"3D BarChart in .NET WinForms\" width=\"508\" height=\"335\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_bar_chart_marketing_team.png 508w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/06\/winforms_bar_chart_marketing_team-300x197.png 300w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><\/a><p id=\"caption-attachment-340\" class=\"wp-caption-text\">3D BarChart in .NET WinForms<\/p><\/div>\n<p><strong>Scrolling the chart:<\/strong><\/p>\n<p>We set the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?P_MindFusion_Charting_WinForms_Chart_ResizeType_0.htm\">ResizeType<\/a> to &#8220;<a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/masterchart\/index.htm?T_MindFusion_Charting_WinForms_ResizeType.htm\">Scrollable<\/a>&#8220;. This way we can scroll to see all data on the chart without the need to increase the size of the chart and let it take too much space.<\/p>\n<p><code>barChart1.ResizeType = MindFusion.Charting.WinForms.ResizeType.Scrollable;<\/code><\/p>\n<p>The sample is available for download from here:<\/p>\n<p align=\"center\"><a href=\"https:\/\/mindfusion.dev\/_samples\/GanttChart.zip\">Download WinForms Working Hours Bar Chart Sample<\/a><\/p>\n<p>A trial version of MindFusion.Charting for WinForms is available from here:<\/p>\n<p align=\"center\"><a href=\"https:\/\/www.mindfusion.dev\/ChartWinFormsTrial.zip\">Download MindFusion.Charting for WinForms<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we will explore how to create a bar chart that shows the weekly working hours for each member of a team. We use MindFusion.Charting for WinForms component. The Type of the Bar Chart We decide to use &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/working-hours-bar-chart-in-winforms\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[61,74],"tags":[79,70,39,102,106,29],"class_list":["post-334","post","type-post","status-publish","format-standard","hentry","category-charting-2","category-sample-code","tag-bar-chart","tag-chart","tag-component","tag-custom-labels","tag-grid","tag-winforms"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-5o","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=334"}],"version-history":[{"count":5,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/334\/revisions"}],"predecessor-version":[{"id":2441,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/334\/revisions\/2441"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}