使用ms图表控件在图表上显示多个标签 [英] showing multiple labels on graph using ms chart controls

查看:55
本文介绍了使用ms图表控件在图表上显示多个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ms-chart控件创建一个列图。

我从以下格式获取数据库中的值

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已经尝试了






i have tried

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());
}



我想在图表上显示日期。



我想要显示所有值在图表上计算日期和状态,以便用户可以理解

就像在这个19/08 / 2014,10呼叫被撤消和15个已完成。但我只能显示图表上的两个值。如何显示所有三个值。





帮帮我..

提前谢谢..


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..

推荐答案

我只是使用日期来缩放X轴,然后将计数器作为Y轴,然后制作两个不同的colums代表完成和撤消的颜色。



它应该更容易理解,也可能更容易理解。


$ b $例如:

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



你明白了吗?



如果你不想这样,那么请更好地解释你想做什么。



在OP评论后添加

然后制作6个不同的栏每天。问题出在哪里?



我可以理解你更喜欢将计数放在最高位,因为在10到11之间或者关闭数字并不容易看看酒吧长度的差异。



如果MS-Chart不允许你把标签放在那里(但我认为应该可以) ,然后您可以考虑创建自己的标签并将它们移动到正确的位置的变通方法。它需要一些数学但是应该不那么困难。



示例:

每个状态栏宽20像素,每个+柜台中的1个高5个像素。



您可以获得图表绘制区域的窗口位置,然后是:



不要忘记这只是一个例子,所以你看看如何做一个变通办法




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
)



一旦你有了自己的位置,那就在那里写下你自己的计数器标签。 br />


如果你按照我的方式进行操作,那么代表每个条形图的内容会更容易,你可以在图表下方得到每个条形图。 Y轴值固定,X轴值与计数器相同





另一方面...

老实说,如果你每天有6个酒吧,那么你将会非常快地离开太空。在这种情况下,我会建议你使用线性grafic,每个状态得到一条线和一个颜色。



我的意思是图形的艺术,如


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

   .___.     .      .
  /     \   / \.__./
 /       \./
/



它会给你有更多的地方可以画更多的日子,保持它的可读性并简化它,因为你每天只有一个X坐标,只需要为每个状态计算Y坐标(以防万一MS-Chart没有自动为你做。)


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).


这篇关于使用ms图表控件在图表上显示多个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆