Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a column graph using ms-chart controls.
I am getting values from database in below format
count     Date          status
10      19/08/2014      Undone
15      19/08/2014       Done
11      20/08/2014      Undone
20      20/08/2014       Done



i have tried

C#
DataTable dt = GetData(query);

DataTable dt1 = GetData(query1);

foreach (DataRow row in dt.Rows)
{
   columnchart.Series["Ser1"].Points.AddXY(row["Status"].ToString(), row["count"].ToString());
}
foreach (DataRow row in dt1.Rows)
{
   columnchart.Series["Ser2"].Points.AddXY(row["Status"].ToString(), row["count"].ToString());
}

I want to show the dates as well on the graph.

I want to show all the values count date and status on graph so that the user can understand
like on this 19/08/2014,10 calls were undone and 15 were done.But i am able to display only two values from table on graph.How to display all three values.


Help me out..
Thanks in advance..
Posted
Updated 20-Aug-14 23:17pm
v3
Comments
Nelek 21-Aug-14 4:53am    
Please don't think we can read minds or do astral projections to see your monitor. If you need help, the least you could do is to add some relevant code to your question or to explain your problem in such a way, that the users of CP can understand it. Otherwise, nobody will be able to help you.

Please use the "improve question" and add relevant information or a piece of code envolved.

What have you tried?[^]

1 solution

I would just use the dates to scale the X-Axis, then the counters as Y-Axis and then make two colums with different colours to represent done and undone.

It should be much easier and probably easier to understand too.

example:
                                       __20__
20                                     |     |                   U = Undone
              __15__                   |     |                   D = Done
15            |     |                  |     |                   X = Status number 3
     __10__   |     |         __11__   |     |                   Y = Status number 4
10   |     |  |     |         |     |  |     |                   ... and so on
     |     |  |     |         |     |  |     |
5    |     |  |     |         |     |  |     |
     |  U  |  |  D  |         |  U  |  |   D |
------------------------------------------------------------------------------------
         19/08/2014               20/08/2014

Do you get the idea?

If you don't want it like that, then please explain better what you want to do.

addition after OP's comment
Then make 6 different bars for each day. Where is the problem?

I can understand that you prefer to put the count at top of bar because between 10 and 11 or close numbers won't be really easy to see the difference on the lenght of the bar.

If the MS-Chart doesn't allow you to put the labels there (but I think it should be possible), then you can think on a workaround creating your own labels and moving them to the right places. It will need a bit maths but it should be not so difficult.

Example:
Each status bar is 20 pixels wide and each +1 in the counter is 5 pixels high.

You could get the window-pos of the chart drawing area and then something like:

Don't forget this is just an example so you see how it could be done as a workaround

Label 1 X = 
50 pixels for Y-Axis legends and a bit empty space to the first bar
+ 
2 or 3 pixels so that the label is centered in the bar
+
(20 pixels * (which bar - 1) //// in case of 6 stati, you would have 0 to 5 as values
+
(40 pixels * (Which day position - 1)) /// in your case 19.08 would give 0, 20.08 would give 1

and
Label 1 Y = 
Height of the chart 
-  ///minus if the 0,0 coordinates are in top-left corner as usual, if not... then just adapt
(
40 pixels for the X-Axis legends /// you don't need more because 0 counter is in X-Axis itself
+
(5 pixels/unit * (Counter + 1)) /// counter + 1 because you want a bit space from the bar to the label
)

Once you have your position, then just write your own counter label there.

To put what represents each bar is easier if you just do it as I did, you can wirte below the chart what each is. The Y-Axis value would be fixed and the X-Axis values would be the same as for the counter


On the other hand...
To be honest, if you have 6 bars a day, you are going to be out of space very fast. In that case I would recommend you to use a linear grafic where each status get a line and a colour.

I mean the art of graphic like
   .___.     .      .
  /     \   / \.__./
 /       \./
/

It will give you much more place to draw more days, keeping it readable, and simplifying it, because you have only one X-Coordinate each day, only need to calculate the Y-Coordinate for each status (just in case the MS-Chart doesn't do it automatically for you).
 
Share this answer
 
v6
Comments
Herman<T>.Instance 21-Aug-14 6:02am    
creative drawing! but my 5
Nelek 21-Aug-14 13:04pm    
Thanks. If you liked, you will like it more now after the edit ;P
Herman<T>.Instance 21-Aug-14 16:50pm    
true!
pwavell 21-Aug-14 6:02am    
i want to display count also on top of bars as labels and explain which bar represents done/undone.. lets say in the form of legends,bcoz the status values are more than 6.the date section is correct i.e on x axis.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900