{"id":482,"date":"2013-09-26T14:06:54","date_gmt":"2013-09-26T14:06:54","guid":{"rendered":"http:\/\/mindfusion.eu\/blog\/?p=482"},"modified":"2021-01-08T15:54:50","modified_gmt":"2021-01-08T15:54:50","slug":"asp-net-bar-chart-with-custom-labels","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/asp-net-bar-chart-with-custom-labels\/","title":{"rendered":"ASP.NET Bar Chart with Custom Labels"},"content":{"rendered":"<p>In this blog post we will look on how to build a bar chart with multiple series, custom X-labels and inner labels using MindFusion.Charting for ASP.NET control.<\/p>\n<p><strong>1. General Appearance of the Chart<\/strong><\/p>\n<p>We want to show three data series and we want to show the first values of each series in a cluster, then second cluster with the second values of each series etc. In order to render the bars in this order we set the <a title=\"Bar Type\" href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_BarChart_BarType_0.htm\">BarType<\/a> property to <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?T_MindFusion_Charting_BarType.htm\">BarType.Clustered3D<\/a>. We correct the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_AxesChart_Depth3D_0.htm\">Depth3D<\/a> to make the bars less thick and increase the distance between each series with <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_BarChart_DistBtwBars_0.htm\">DistBtwBars<\/a>. We make the bars wider, setting <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_BarChart_BarWidth_0.htm\">BarWidth<\/a> to 30.<\/p>\n<pre>    \/\/general appearance\n    BarChart1.BarType = MindFusion.Charting.BarType.Clustered3D;\n    BarChart1.BarWidth = 30f;        \n    BarChart1.Depth3D = 15f;\n    BarChart1.DistBtwBars = 10f;\n<\/pre>\n<p><strong>2. Grid<\/strong><\/p>\n<p>Our bars are vertical e.g. it is a column chart, so we would like to have a horizontal grid. We set the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_AxesChart_GridType_0.htm\">GridType<\/a> property to <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?T_MindFusion_Charting_GridType.htm\">GridType.HorScale<\/a> and we set the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_AxesChart_AltGridBrush_0.htm\">AltGridBrush<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_AxesChart_GridBrush_0.htm\">GridBruh<\/a> to different gray colors to give us nice alternating grid stripes. For the outlining of the whole plot area we use the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?CC_P_MindFusion_Charting_AxesChart_PlotAreaOutlinePen_0_0.htm\">PlotAreaOutlinePen<\/a>.<\/p>\n<pre>    \/\/grid settings\n    BarChart1.GridBrush= new MindFusion.Drawing.SolidBrush(System.Drawing.Color.FromArgb(242, 239, 224));\n    BarChart1.GridPen= new MindFusion.Drawing.Pen(System.Drawing.Color.FromArgb(204, 196, 185));\n    BarChart1.GridType = MindFusion.Charting.GridType.HorScale;\n    BarChart1.PlotAreaOutlinePen = new MindFusion.Drawing.Pen(System.Drawing.Color.FromArgb(204, 196, 185));\n<\/pre>\n<p><strong>3. Labels Inside Bars<\/strong><\/p>\n<p>The labels inside bars show the data of each bar &#8211; this is done by setting the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_BarChart_InnerLabelType_0.htm\">InnerLabelType<\/a> property to <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?T_MindFusion_Charting_LabelType.htm\">LabelType.Data<\/a>. We use a white <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_Chart_LabelBrush_0.htm\">LabelBrush<\/a> to draw the labels and set their <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_BarChart_InnerLabelBorder_0.htm\">InnerLabelBorder<\/a> to <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?T_MindFusion_Charting_Border.htm\">Border.RoundedRect<\/a>. The background of the inner labels is set to gray.<\/p>\n<pre>    \/\/inner labels settings\n    BarChart1.InnerLabelBackground = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.FromArgb(112, 128, 144));\n    BarChart1.InnerLabelBorder = MindFusion.Charting.Border.RoundedRect;\n    BarChart1.InnerLabelType = MindFusion.Charting.LabelType.Data; \n    BarChart1.LabelBrush = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 255, 255));\n<\/pre>\n<p><strong>4. Title<\/strong><\/p>\n<p>We want not only title but also second title &#8211; or a subtitle. That&#8217;s why we use both the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_Chart_TitleText_0.htm\">TitleText<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_Chart_SubTitleText_0.htm\">SubTitleText<\/a> properties. We leave no distance between them &#8211; we set <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_Chart_SubTitleOffset_0.htm\">SubTitleOffset<\/a> to 0. But we would like the two titles to be well above the plot area, that&#8217;s why we set bigger <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_Chart_TitleOffset_0.htm\">TitleOffset<\/a>.<\/p>\n<pre>    \/\/title and subtitle\n    BarChart1.SubTitleOffset = 30;\n    BarChart1.SubTitleText = \"all major continents\";\n    BarChart1.TitleOffset = 0;\n    BarChart1.TitleText = \"Sales\";\n<\/pre>\n<p><strong>5. Labels at the Axes<\/strong><\/p>\n<p>The X-labels are custom text &#8211; we set them with <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?P_MindFusion_Charting_WebForms_AxesChart_XLabels_0.htm\">XLabels<\/a>. The title of the Y-axis is rotated, so we use<a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/chartingaspnet\/index.htm?T_MindFusion_Charting_AxisLabelOrientation.htm\"> LabelOrientation.BottomToTop<\/a>.<\/p>\n<pre>    \/\/axes labels settings\n    BarChart1.XAxisSettings.LabelSeriesIndex = 1;\n    BarChart1.XLabels.Clear();\n    BarChart1.XLabels.Add(new List(){ \"Europe\", \"Asia\", \"North America\", \"South America\"});\n    \n    BarChart1.YAxisSettings.TitleLabel = \"in mlns. USD\";\n    BarChart1.YAxisSettings.TitleLabelOrientation = MindFusion.Charting.LabelOrientation.BottomToTop;\n<\/pre>\n<p>Here is a screenshot of the final chart:<\/p>\n<div id=\"attachment_486\" style=\"width: 743px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/09\/asp_bar_chart_with_labels.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-486\" class=\"size-full wp-image-486\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/09\/asp_bar_chart_with_labels.png\" alt=\"ASP.NET Bar Chart with Custom Labels\" width=\"733\" height=\"650\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/09\/asp_bar_chart_with_labels.png 733w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2013\/09\/asp_bar_chart_with_labels-300x266.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/a><p id=\"caption-attachment-486\" class=\"wp-caption-text\">ASP.NET Bar Chart with Custom Labels<\/p><\/div>\n<p>The sample can be downloaded from here:<\/p>\n<p align=\"center\"><a title=\"ASP.NET Bar Chart with Labels\" href=\"https:\/\/mindfusion.dev\/_samples\/LabelsBarChart.zip\">Download ASP.NET Bar Chart with Labels Sample<\/a><\/p>\n<p>The trial version of MindFusion.Charting for ASP.NET can be downloaded directly from the link below. It contains many more samples and tutorials:<\/p>\n<p align=\"center\"><a href=\"https:\/\/www.mindfusion.dev\/WebChartingTrial.zip\">Download MindFusion.Charting for WebForms Trial Version<\/a><\/p>\n<p><em>About MindFusion.Charting for WebForms:<\/em> A powerful WebForms control that lets programmers add compelling charts in any ASP.NET application. With the component you can design and create any bar, column, line, area, scatter, bubble, radar, polar, doughnut and pie chart. Its elegant API includes data binding, themes, hit-testing, zoom, drill-down, wizards and many more.<\/p>\n<p>The control takes advantage of the rich capabilities of Microsoft WebForms but its functionality does not bring excess complexity. The API is very easy to understand, all the features are duly documented. Numerous samples and step-by-step tutorials let you learn quickly how to tailor the tool in order to meet best your needs.<\/p>\n<p>Details about the various features of the control are provided <a href=\"http:\/\/mindfusion.dev\/features-webchart.html\">here.<\/a> <a href=\"http:\/\/www.mindfusion.co\/demos\/index.html?Control=Charting\">The online demo<\/a> will give you an overview of the control&#8217;s rich capabilities. Licenses, prices and discounts are listed at <a href=\"http:\/\/mindfusion.dev\/buy-webchart.html\">the buy page.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post we will look on how to build a bar chart with multiple series, custom X-labels and inner labels using MindFusion.Charting for ASP.NET control. 1. General Appearance of the Chart We want to show three data series &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/asp-net-bar-chart-with-custom-labels\/\">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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[61,74],"tags":[7,142,70,143,102,106,144],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-charting-2","category-sample-code","tag-asp-net","tag-bar","tag-chart","tag-charting-control","tag-custom-labels","tag-grid","tag-webforms-chart"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-7M","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/482","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=482"}],"version-history":[{"count":9,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"predecessor-version":[{"id":2464,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions\/2464"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}