图多系列不同长度的生成重复X轴 [英] Chart Multiple series different length generate duplicate x axis

查看:253
本文介绍了图多系列不同长度的生成重复X轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看从我的web应用程序ASP.NET 4.0这张图片。

你可以本身的线路有不同的长度。也有重复的x轴的条目。

蓝色意甲缺少一个数据点,黄没有。
问题1:
如何将它们对齐,以便所述X轴保持不变。目前,即时通讯这样做。并线一样长?
问题2:有没有一种方法,使图表的互动,让你可以将某些按住鼠标就行了从这一点看数据,使用ASP.NET

  INT amountofrows = Convert.ToInt32(dt.Rows [0] [安塔尔]的ToString());的for(int i = 0; I< amountofrows;我++)
{
    清单<串GT; xvals =新的List<串GT;();
    清单<&小数GT; yvals =新的List<&小数GT;();
    字符串serieName = dt.Rows [I] [doman_namn]的ToString()。
    Chart1.Series.Add(serieName);
    Chart1.Series [I] .ChartType = SeriesChartType.Line;    的foreach(在dt.Rows的DataRow博士)
    {
        尝试
        {
            如果(String.Equals(serieName,博士[doman_namn]。的ToString(),StringComparison.Ordinal))
            {
                xvals.Add(DR [ranking_date]的ToString());
                yvals.Add(Convert.ToDecimal(DR [ranking_position]的ToString()));
            }        }
        赶上(例外)
        {            抛出新的InvalidOperationException异常(Diagrammet昆德INTE ritas UPP);
        }
    }
    尝试
    {
        Chart1.Series [serieName] .XValueType = ChartValueType.String;
        Chart1.Series [serieName] .YValueType = ChartValueType.Auto;
        Chart1.Series [serieName] .Points.DataBindXY(xvals.ToArray(),yvals.ToArray());
        Chart1.DataManipulator.InsertEmptyPoints(1,IntervalType.Days,serieName);
    }
    赶上(异常前)
    {
        抛出新的InvalidOperationException异常(ex.Message);
    }
}Chart1.DataBind();
Chart1.Visible =真;


解决方案

这就是答案!

感谢您指出了这一点JBL!

 的foreach(在Chart1.Series serien System.Web.UI.DataVisualization.Charting.Series)
     {
                的foreach(System.Web.UI.DataVisualization.Charting.DataPoint数据点在serien.Points)
                {
                    如果(dataPoint.YValues​​ [0] == 0)
                    {
                       dataPoint.IsEmpty = TRUE;
                    }
                }                serien.Sort(PointSortOrder.Ascending,sortBy :(X));
     }

Look at this picture from my web application ASP.NET 4.0.

As you can se the lines have a different length. Also there is duplicate x axis entry.

The blue serie has a missing datapoint, the yellow does not. Question 1: How do I align them so the x- axis stays the same. Currently im doing this. And make the lines equally long? Question 2: Is there a way to make the chart interactive so that you can some and hold the cursor on the line to see data from that point, using ASP.NET?

int amountofrows = Convert.ToInt32(dt.Rows[0]["antal"].ToString());

for (int i = 0; i < amountofrows; i++)
{
    List<string> xvals = new List<string>();
    List<decimal> yvals = new List<decimal>();
    string serieName = dt.Rows[i]["doman_namn"].ToString();
    Chart1.Series.Add(serieName);
    Chart1.Series[i].ChartType = SeriesChartType.Line;

    foreach (DataRow dr in dt.Rows)
    {
        try
        {
            if (String.Equals(serieName, dr["doman_namn"].ToString(), StringComparison.Ordinal))
            {
                xvals.Add(dr["ranking_date"].ToString());
                yvals.Add(Convert.ToDecimal(dr["ranking_position"].ToString()));
            }

        }
        catch (Exception)
        {

            throw new InvalidOperationException("Diagrammet kunde inte ritas upp");
        }
    }
    try
    {
        Chart1.Series[serieName].XValueType = ChartValueType.String;
        Chart1.Series[serieName].YValueType = ChartValueType.Auto;
        Chart1.Series[serieName].Points.DataBindXY(xvals.ToArray(), yvals.ToArray());
        Chart1.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, serieName);
    }
    catch (Exception ex)
    {
        throw new InvalidOperationException(ex.Message);
    }
}

Chart1.DataBind();
Chart1.Visible = true;

解决方案

This was the answer!

Thanks for pointing that out JBL!

     foreach (System.Web.UI.DataVisualization.Charting.Series serien in Chart1.Series)
     {
                foreach(System.Web.UI.DataVisualization.Charting.DataPoint dataPoint in serien.Points)
                {
                    if (dataPoint.YValues[0] == 0)
                    { 
                       dataPoint.IsEmpty = true;
                    }
                }

                serien.Sort(PointSortOrder.Ascending,sortBy:("X"));
     }

这篇关于图多系列不同长度的生成重复X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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