0

我有一个 ASP 图表,它使用计时器刷新更新面板,模拟“实时”图表(基本上是http://www.4guysfromrolla.com/articles/121609-1.aspx下“创建实时图表”下的指南) . 我添加了允许您向图表动态添加系列的功能,但新系列始终从 x 轴上的 0 点开始。当图表上的数据已经“滴答”了一段时间时,这是一个问题,因为新系列从 0 开始并出现“移动”到左侧。如何将该系列向右移动以使其 x 轴时间与其他“较旧”系列的时间对齐?

这是一个示例的图片——首先添加了蓝线,几秒钟后添加了黄线。

http://content.screencast.com/users/johnkemnetz/folders/Jing/media/c3c954fc-66c1-4d4d-a272-3e4b4f211e5a/ex.png

4

1 回答 1

0

我自己想出了这个问题。这是我所做的:

if(chart.Series.Count > 0)
{
    /*Get the most recent Y-val to fill in empty spaces (if you fill with 0,
     *you'll end up with a "leap" on the first visible data point)*/
    double hiddenData = getMostRecentValue(newSeriesName);
    foreach (DataPoint dp in chart.Series[0].Points)
    {
        newSeries.AddXY(dp.XValue, hiddenData);
        newSeries.Last().Color = Color.Transparent;
    }
}
//etc. add newSeries to chart

基本上,我为新系列中不存在的所有数据点添加“虚拟值”,然后使用 Color.Transparent 隐藏它们。
希望这对其他人有帮助!

于 2012-07-05T14:37:33.443 回答