我有一个快速折线图系列,其中X上有DateTime
和Y double
值 - 系列使用这样的方法添加到图表中:
public virtual bool AddOrUpdateSeries(int caIndex, Series newSeries, bool visibleInLegend)
{
var chartArea = GetChartArea(caIndex);
if (chartArea == null) return false;
var existingSeries = _chart.Series.FirstOrDefault(s => s.Name == newSeries.Name);
if (existingSeries != null)
{
existingSeries.Points.Clear();
AddPoints(newSeries.Points, existingSeries);
}
else
{
newSeries.ChartArea = chartArea.Name;
newSeries.Legend = chartArea.Name;
newSeries.IsVisibleInLegend = visibleInLegend;
newSeries.BorderWidth = 2;
newSeries.EmptyPointStyle = new DataPointCustomProperties { Color = Color.Red };
_chart.Series.Add(newSeries);
}
return true;
}
如您所见,我将空点的样式设置为红色。
系列中添加的第一点如下:
正如您所看到的,前两个点具有相同的Y值,但此外 -
第一个设置了IsEmpty
标志。
使用这样的代码将空点添加到系列中:
series.Points.Add(new DataPoint
{
XValue = _beginOADate,
YValues = new[] { firstDbPoint.Y },
IsEmpty = true
});
其中_beginOADate
为双OADate值= 42563
= 12/07/2016 00:00 as DateTime
。
第二个点的DateTime
是15/08/2016 22:20
当图表以X轴的开头显示时,一切看起来都不错,如下图所示 - 空数据点从2016年7月12日开始,持续到2016年8月15日。
但是,当我在X上滚动一个位置时,没有显示空数据点的红线 - 而是显示空数据点行的整个可见部分,因为它是非空的:
有人知道如何修复此行为,以便从Empty datapoint开始直到第一个非空数据点的整行始终以红色显示?
当然,虚拟解决方案是在第一个非空点附近添加一个额外的空数据点,但我不喜欢这个解决方案。
答案 0 :(得分:2)
ChartType.FastLine
比简单Line
图表快得多,但速度要快得多,这使得渲染得到了一些简化,这意味着不支持所有图表功能:
FastLine图表类型是折线图的变体 显着缩短了包含a的系列的绘制时间 非常大量的数据点。在以下情况下使用此图表 使用非常大的数据集,渲染速度至关重要。
FastLine图表中省略了一些图表功能以进行改进 性能。省略的功能包括控制点水平 视觉属性,标记,数据点标签和阴影。
不幸的是EmptyPointStyle
是一个'点级视觉属性'。
所以你需要决定哪个更重要:原始速度或空DataPoints
的直接和合理处理。
(我有预感你会选择'虚拟解决方案',这是一流的解决方案; - )