Cracked it. @Alex Li-MSFT 's answer above was helpful and had the effect of removing the earlier (pre-December in the illustration above) datapoints, but it also removed the points from the line for the subsequent months as well (although this didn't happen, strangely, if Alex's code is included in a subsequent event, triggered after the chart is created and populated). This is what I got:
But I got the result I needed by creating the full 12 months Keys in Series[0] and then simply populating only the months I needed to show in the line for Series1 (i.e. excluding any where the value was null):
It is essential to add the first Series with the full range of keys you need on your chart first (noting that the value of the first Key of the first Series cannot be null, as this produces an ''Object reference not set to an instance of an object' run-time exception when you try to add your KeyValuePairs list to your DataPointSeries ItemsSource). My final code is:
//Series[0]: chart columns
List<KeyValuePair<string, decimal?>> netSpendList = new List<KeyValuePair<string, decimal?>>();
for (int i = 0; i < 12; i++)
{
if (monthResult[i].Balance.HasValue)
{
netSpendList.Add(new KeyValuePair<string, decimal?>(months[startMonth - 1 + i < 0 ? 12 : startMonth - 1 + i], decimal.Parse(((decimal)monthResult[i].income - (decimal)monthResult[i].expense).ToString("N2"))));
}
else if (i == 0) //Note, first Value in the Series cannot be null
{
netSpendList.Add(new KeyValuePair<string, decimal?>(months[startMonth - 1 + i < 0 ? 12 : startMonth - 1 + i], 0M));
}
else
{
netSpendList.Add(new KeyValuePair<string, decimal?>(months[startMonth - 1 + i < 0 ? 12 : startMonth - 1 + i], null));
}
}
(cashflowChart.Series[0] as DataPointSeries).ItemsSource = netSpendList;
//Series[1]: Chart line (partial only)
List<KeyValuePair<string, decimal?>> balanceList = new List<KeyValuePair<string, decimal?>>();
decimal? balance = null;
for (int i = 0; i < 12; i++)
{
if (monthResult[i].Balance.HasValue)
{
balance = decimal.Parse(((decimal)monthResult[i].Balance).ToString("N2"));
KeyValuePair<string, decimal?> balancePoint = new KeyValuePair<string, decimal?>(months[startMonth - 1 + i < 0 ? 12 : startMonth - 1 + i], balance ?? balance);
balanceList.Add(balancePoint);
}
}
(cashflowChart.Series[1] as DataPointSeries).ItemsSource = balanceList;