Click here to Skip to main content
15,883,901 members
Articles / Desktop Programming / WPF

Interactive 3D bar chart custom control in WPF with rotation, touch-sense display, and databinding support

Rate me:
Please Sign up or sign in to vote.
4.69/5 (37 votes)
29 Mar 2009CPOL10 min read 247.9K   8.1K   73  
Create a WPF 3D Bar chart in your .NET application easily. You can create interactive 3D bar charts in seconds using this WPF 3D bar chart custom control. You can even databind your input to see the '3D chart bar change live as you enter your input' effect.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Media3D;
using System.Windows.Media;

namespace Wpf3DChartTutorial
{
    internal class HitDetails
    {
        private Point3D p0, p1, p2, p3, pointToWrite;
        private Color barColor;
        Point3D pointToStart;
        double barHeight, barWidth;
        private string xItem, yItem, zItem;
        bool showValue;
        StringBuilder strToDisplay;

        public HitDetails(string XItemParam, string YItemParam, string ZItemParam, Point3D P0, Point3D P1, Point3D P2, Point3D P3, Point3D PointToWrite, Point3D PointToStartParam, double Width, double Height, Color BarColorParam)
        {
            xItem = XItemParam;
            yItem = YItemParam;
            zItem = ZItemParam;
            p0 = P0;
            p1 = P1;
            p2 = P2;
            p3 = P3;
            strToDisplay = new StringBuilder();
            pointToWrite = PointToWrite;
            barColor = BarColorParam;

            pointToStart = new Point3D(PointToStartParam.X, PointToStartParam.Y, PointToStartParam.Z);
            pointToStart.X -= 0.25;
            pointToStart.Z += 0.25;
            barHeight = Height + 0.5;
            barWidth = Width + 0.5;
            Update();
        }

        public void Update()
        {
            strToDisplay.Length = 0;
            strToDisplay.AppendFormat("X={0}; Y={1}; Z={2}", xItem, yItem, zItem);
        }

        public Point3D PointToWrite
        {
            get
            {
                return pointToWrite;
            }
        }

        public string StringToDisplay
        {
            get
            {
                return strToDisplay.ToString();
            }
        }

        public bool ShowValue
        {
            get
            {
                return showValue;
            }

            set
            {
                showValue = value;
            }
        }

        public string XItem
        {
            get
            {
                return xItem;

            }
        }

        public string YItem
        {
            get
            {
                return yItem;
            }
        }

        public string ZItem
        {
            get
            {
                return zItem;
            }
        }

        public Point3D P0
        {
            get
            {
                return p0;
            }
        }

        public Point3D P1
        {
            get
            {
                return p1;
            }
        }

        public Point3D P2
        {
            get
            {
                return p2;
            }
        }

        public Point3D P3
        {
            get
            {
                return p3;
            }
        }

        public Point3D PointToStart
        {
            get
            {
                return pointToStart;
            }
        }

        public double Height
        {
            get
            {
                return barHeight;
            }
        }

        public double Width
        {
            get
            {
                return barWidth;
            }
        }

        public Color BarColor
        {
            get
            {
                return barColor;
            }
        }

    
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions