Chart Multiple series different length generate duplicate x axis

柔情痞子 提交于 2019-12-12 04:33:56

问题


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;

回答1:


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


来源:https://stackoverflow.com/questions/13429934/chart-multiple-series-different-length-generate-duplicate-x-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!