Hi all,
i am making a c# window application,in which i am entering marks of students of individual subjects in database.
Now, how can i pick these values from database dynamically and draw the pie chart and bar graph of these marks.
I want that as i click on button, the graph should be shown(of its marks)..........
i am using Ms access data base for this.
Kindly help me in this...........

Recommended Answers

All 8 Replies

I know this is not what you need, but take a look at this snippet http://www.daniweb.com/code/snippet238532.html. It might give you some ideas on how to construct a barchart.
It just so happens, I'm working on a forms barchart app. I have a form with a Panel and I use the paint event handler of the Panel to do my drawing. I also make use here of a Plot class to get a hold on the coordinates. I will give you the code of this class as is.
My barchart project being under construction, I have not been able to do much testing yet. But I hope you can somehow use it.

namespace BarChart
{
    class Plot
    {
        //class to plot x and y values on a form or panel etc.
        //
        //because on the coordinates start at the upper left corner with 0,0
        //with the y coordinate going down, a little transformation is done here
        //so that x,y coordinates act as normal carthesian coordinates, with 0,0
        //in the left bottom 

        struct PlotPort
        {
            public float minX;
            public float maxX;
            public float minY;
            public float maxY;
        };

        private PlotPort _PlotW;    //"window" of carthesian coordinates
        private Size _ClientArea;   //keeps the pixels info
        private float _Xspan;
        private float _Yspan;

        public Plot() { }

        public Plot(Size Plotarea)
        {
            _ClientArea = Plotarea;
        }

        public Size ClientArea { set { _ClientArea = value; } }

        public void SetOrigin(float Ox, float Oy)
        {
            ///to do!!!!!!!!!!!!!!!!!!!!!!!
        }

        public void SetPlotPort(float minx, float maxx, float miny, float maxy)
        {
            //set the bounderies of the (screen) to real coordinates.
            _PlotW.minX = minx;
            _PlotW.maxX = maxx;
            _PlotW.minY = miny;
            _PlotW.maxY = maxy;
            _Xspan = _PlotW.maxX - _PlotW.minX;
            _Yspan = _PlotW.maxY - _PlotW.minY;
        }

        public void PlotPixel(float X, float Y, Color C, Graphics G)
        {
            Bitmap bm = new Bitmap(1, 1);
            bm.SetPixel(0, 0, C);
            G.DrawImageUnscaled(bm, Convert.ToInt32(TX(X)), Convert.ToInt32(TY(Y)));
        }

        public void PlotBitmap(float X, float Y, Bitmap bm, Graphics G)
        {
            G.DrawImageUnscaled(bm, Convert.ToInt32(TX(X)), Convert.ToInt32(TY(Y)));
        }

        private float TX(float X) //transform real coordinates to pixels for the X-axis
        {
            return (_ClientArea.Width / _Xspan) * X;
            return w); 
        }

        private float TY(float Y) //transform real coordinates to pixels for the Y-axis
        {
            return _ClientArea.Height - (_ClientArea.Height / _Yspan) * Y;// +_ClientArea.Height / 2;
        }
    }
}

Well thanks for your reply ddanbe....
i already have the code of making the bar, pi and other chart statically.....
But i want to know how can i generate these charts dynamically using database, as i mentioned above.........
As i provided a button with each user name, than on clicking on this button it should dynamically pick the corresponding marks of that user from database and draw a chart of this.........
Kindly help mje in this.......
ddnabe if you want the code for making bar chart for static data, i can provide you that.........
So that you can use that in your project........

He thanks avirag. :)
I must tell you, that I'm not that familiar with extracting data from a DB(select statement?), but I know there are guys around here who will gladly help you out!

He thanks avirag. :)
I must tell you, that I'm not that familiar with extracting data from a DB(select statement?), but I know there are guys around here who will gladly help you out!

ok ddanbe..
Here i have attested the application,
may it help you in your project...:)

Thanks very much avirag.
For your DB problem, I suggest to select the database tag (you find tags at the bottom of the C# page) and see what you can find there. If you can't find something usefull, post a new thread more specific about Acces DBs. Succes!

Thanks very much avirag.
For your DB problem, I suggest to select the database tag (you find tags at the bottom of the C# page) and see what you can find there. If you can't find something usefull, post a new thread more specific about Acces DBs. Succes!

Most welcome ddanbe....:)
Well this application is helpful for you or not?
well i cant find database tag ;), can you please tell me from where i can find this.......?

I'm surely going to look at your code and will let you know what I think of it:)
For the tag : when you are reading this, go to the top of this page, select Software Development and choose C#. You are now on the "Main" C# forum window. Go all the way to the bottom, you must see a bunch of words there. Hover with the mouse over them and you see they get highlighted. Now select the word(tag) database. You will be redirected to a list of threads that all have something to do with a database. I find this a very fancy feature of Daniweb!

oh...
thanks again ddanbe...........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.