using System.Web.UI.DataVisualization.Charting.Chart
...but my chart does not draw lines between points of missing data:
As you can see, the 2nd column has a point at 51 on 7/09/2015 and then points are empty until 7/16/2015. I want the chart to draw a line from the point at 7/09/2015 to 7/16/2015.
How can I get this to work?
This is my existing Series
construction:
var series = chart.Series[header] = new Series(header) {
BorderWidth = 2,
ChartArea = DataTable.TableName,
ChartType = SeriesChartType.FastLine,
Color = legendColors[header],
Enabled = true,
Font = new Font("Lucida Sans Unicode", 6f),
XValueMember = "Week",
YValueMembers = header
};
Update 1:
With @jstreet's answer, I am now getting a line drawn. But the value is being represented as if it were 0:
What is expected is the following where thick dashed lines should replace the lines representing a value of 0:
Update 2:
Modified the for-loop
to manually add DataPoint
s to the series
following @jstreet's example for add points in code-behind:
for (int column = 0; column < seriesHeaders.Length; column++) {
var header = seriesHeaders[column];
var series = chart.Series[header] = new Series(header) {
BorderWidth = 2,
ChartArea = DataTable.TableName,
ChartType = SeriesChartType.FastLine,
Color = legendColors[header],
Enabled = true,
Font = new Font("Lucida Sans Unicode", 6f),
XValueMember = "Week",
YValueMembers = header
};
series.EmptyPointStyle.Color = legendColors[header];
series.EmptyPointStyle.AxisLabel = "Empty";
DataTable.Rows
.OfType<DataRow>()
.Select(r => (double)r[header])
.ToList()
.ForEach(v => {
series.Points.Add(new DataPoint(series) {
IsEmpty = v == Double.NaN,
YValues = new double[] { v == Double.NaN ? 0 : v }
});
});
}
...chart still renders what is supposed to be an empty point as a 0
value.
Update 3:
Modified construction of DataPoint
s. Evidently v == Double.NaN
does not evaluate properly:
DataTable.Rows
.OfType<DataRow>()
.Select(r => (double)r[header])
.ToList()
.ForEach(v => {
var isEmpty = Double.IsNaN(v);
var value = new double[] { v == Double.NaN ? 0 : v };
series.Points.Add(new DataPoint() {
IsEmpty = isEmpty,
YValues = value
});
});