我在 WPF 中使用 D3(动态数据显示)。我有绘制动态折线图的代码,这是我的代码片段。
for (int counter = 0; counter < animatedX.Count; counter++)
{
Chart.Trade trade = new Chart.Trade(animatedX[counter], animatedY[counter]);
Color currentLineColor = Colors.Green;
if (previousCloseprice > animatedY[counter])
{
currentLineColor = Colors.Red;
}
Dispatcher.BeginInvoke(new Action(() =>
{
chartLine.LinePen = new Pen(new SolidColorBrush(currentLineColor), 3);
}));
_chartValue.AppendAsync(Dispatcher, trade);
Thread.Sleep(100);
}
从上面的代码中,我可以用单色绘制动画图。previousCloseprice > animatedY[counter]
当这种情况为真时,它会更改线条颜色但会转换整个线条颜色。我希望图表线条应该是红色和绿色的组合,根据(健康)状况