适合图表区域中的所有图例 [英] Fit all legends in the chart area

查看:76
本文介绍了适合图表区域中的所有图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server中有一个表有大约一百列。我在ASP.Net中有一个图表,它从数据库中检索数据并显示为折线图。因此每列都显示为一条线,因此图表将有大约一百行。一切都工作得很好但我面临的唯一问题是我无法将所有传说都放在一个图表区域中。就像我进一步拉伸我的图表一样,我可以看到更多的传说,但我想让所有的图例自动适应图表区域。



什么我试过了:



下面是我试过的代码。

There is a table in SQL Server which has about hundred columns. I have a chart in ASP.Net which is retrieving data from the database and displaying as a line chart. So each columns is being displayed as a line so the chart will have about hundred lines. Everything is working perfectly fine but the only issue I am facing is that I am not being able to fit all the legends in one Chart Area. Like the further i stretch my chart, the more number of legends I can see but I want all the legends to fit automatically in the Chart Area.

What I have tried:

Below is my code that I have tried.

SqlCommand cmd = new SqlCommand(storedProcedure, connection);   
 cmd.CommandType = CommandType.StoredProcedure;
 con.Open();        
 SqlDataAdapter da = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
 da.Fill(ds);

int num = ds.Tables[0].Columns.Count - 1;
   for (int i = 1; i <= num; i++)
        {
            chart1.Series.Add(ds.Tables[0].Columns[i].ColumnName);

        chart1.Series[i].ChartArea = "ChartArea1";

        chart1.Series[i].YValueMembers = ds.Tables[0].Columns[i].ColumnName;
        chart1.Series[i].XValueMember = "Time";
        chart1.Series[i].ChartType = SeriesChartType.Line;

        chart1.Legends.Add(new Legend("Legend" + i.ToString()));
        chart1.Series[i].Legend = "Legend" + i.ToString();
        chart1.Series[i].IsVisibleInLegend = true;
        chart1.Legends["Legend" + i.ToString()].Docking = Docking.Right;
        chart1.Legends["Legend" + i.ToString()].DockedToChartArea = "ChartArea1";
    }

    chart1.DataSource = ds;
    chart1.DataBind();

    con.Close();

推荐答案

1)尝试Docking.Top / Left而不是Right 。



2)使图表区域大小与您正在处理的图例数量相关。



3)创建你自己的自定义(控制;窗口)来显示你的极端传奇数量。



4)考虑可能有太多的传说,你需要与用户坐下来,并达成一些合理的妥协。



5)兔子的罕见限制是7;大多数人也是如此。
1) Trying Docking.Top / Left instead of "Right".

2) Make the chart area "size" a function of the number of legends your are processing.

3) Create your own "custom" (control; window) for displaying your "extreme" legend counts.

4) Consider that maybe there are "too many" legends and you need to have a sit-down with the user and come to some "reasonable" compromise.

5) A rabbit's "rare" limit is 7; so is most humans'.


这篇关于适合图表区域中的所有图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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