BarChart.cs :  » Charting-Reporting-Tools » googlechartsharp » GoogleChartSharp » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Charting Reporting Tools » googlechartsharp 
googlechartsharp » GoogleChartSharp » BarChart.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleChartSharp{
    /// <summary>
    /// The orientation of the bars.
    /// </summary>
    public enum BarChartOrientation
    {
        /// <summary>
        /// Bars will be positioned vertically
        /// </summary>
        Vertical,

        /// <summary>
        /// Bars will be positioned horizontally
        /// </summary>
        Horizontal
    }

    /// <summary>
    /// Bar chart style when using multiple data sets
    /// </summary>
    public enum BarChartStyle
    {
        /// <summary>
        /// Multiple data sets will be stacked.
        /// </summary>
        Stacked,

        /// <summary>
        /// Multiple data sets will be grouped.
        /// </summary>
        Grouped
    }

    /// <summary>
    /// Bar Chart
    /// </summary>
    public class BarChart : Chart
    {
        BarChartOrientation orientation;
        BarChartStyle style;
        int barWidth;
        double zeroLine = 0;

        /// <summary>
        /// Create a bar chart
        /// </summary>
        /// <param name="width">Width in pixels</param>
        /// <param name="height">Height in pixels</param>
        /// <param name="orientation">The orientation of the bars.</param>
        /// <param name="style">Bar chart style when using multiple data sets</param>
        public BarChart(int width, int height, BarChartOrientation orientation, BarChartStyle style)
            : base(width, height)
        {
            this.orientation = orientation;
            this.style = style;
        }

        /// <summary>
        /// Set the width of the individual bars
        /// </summary>
        /// <param name="width">Width in pixels</param>
        public void SetBarWidth(int width)
        {
            this.barWidth = width;
        }

        /// <summary>
        /// Specify a zero line
        /// </summary>
        /// <param name="zeroLine"></param>
        public void SetZeroLine(double zeroLine)
        {
            this.zeroLine = zeroLine;
        }

        /// <summary>
        /// Return the chart identifier used in the chart url.
        /// </summary>
        /// <returns></returns>
        protected override string urlChartType()
        {
            char orientationChar = this.orientation == BarChartOrientation.Horizontal ? 'h' : 'v';
            char styleChar = this.style == BarChartStyle.Stacked ? 's' : 'g';

            return String.Format("b{0}{1}", orientationChar, styleChar);
        }

        /// <summary>
        /// Collect all the elements that will make up the chart url.
        /// </summary>
        protected override void collectUrlElements()
        {
            base.collectUrlElements();
            if (this.barWidth != 0)
            {
                base.urlElements.Enqueue(String.Format("chbh={0}", this.barWidth));
            }
            if (this.zeroLine != 0)
            {
                base.urlElements.Enqueue(String.Format("chp={0}", this.zeroLine));
            }
        }

        /// <summary>
        /// Return the chart type for this chart
        /// </summary>
        /// <returns></returns>
        protected override ChartType getChartType()
        {
            return ChartType.BarChart;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.