I am getting a null object error (nothing more specific unfortunately) when creating the chart below using the .NET Core library:
var chart = new Highcharts
{
ID = $"chart_{categoryGuid.ToString().Replace("-", "")}",
Chart = new Chart
{
Height = "400",
Type = ChartType.Column,
Style = new Hashtable { { "FontFamily", "Segoe UI" } },
BackgroundColor = "transparent",
},
Credits = new Credits { Enabled = false },
Title = new Title { Text = categoryTitle },
XAxis =
[
new XAxis
{
Categories = optionCategoryResults.Select(c => c.optionTitle).ToList(),
Crosshair = new XAxisCrosshair()
}
],
YAxis =
[
new YAxis
{
Title = new YAxisTitle {Text = "Relative Score"},
}
],
Tooltip = new Tooltip
{
Shared = true,
PointFormat = "<span style="color:{point.color}">u25CF</span> Score: <b>{point.y:.1f}</b><br/>"
},
PlotOptions =
{
Column = new PlotOptionsColumn
{
Stacking = PlotOptionsColumnStacking.Normal,
Animation = new Animation
{
Duration = 2000,
Easing = "easeOutBounce"
}
}
},
Legend =
{
Enabled = false
},
Series = categoryResultsSeries
};
I’ve checked that each of the variables I created, such as categoryGuid, categoryTitle, optionCategoryResults, categoryResultsSeries are correct. I’ve even tried hard coding them and/or removing them completely (if possible), and still get the same error.
Note that this code works fine with 11.4.1, but does not with 11.4.6, and the highcharts changelog does not show any breaking changes, although clearly there has been.
Any ideas?
EDIT: Adding full stack trace – although it’s not particularly helpful as far as I can see:
Object reference not set to an instance of an object.
at ResiliencyAssessment.Helpers.Charting.CreateCategorySummaryScoreChart(Guid categoryGuid, String categoryTitle, OptionCategoryResult[] optionCategoryResults) in D:LinQuestShareResiliencyCode ProjectsSMEBasedAssessmentToolResiliencyAssessmentHelpersCharting.cs:line 37
6
You should create specific objects, not anonymous ones. The below code should work correctly:
var chart = new Highcharts
{
ID = $"chart_8",
Chart = new Chart
{
Height = "400",
Type = ChartType.Column,
Style = new Hashtable { { "FontFamily", "Segoe UI" } },
BackgroundColor = "transparent",
},
Credits = new Credits { Enabled = false },
Title = new Title { Text = "categoryTitle" },
XAxis = new List<XAxis>
{
new XAxis
{
Categories = new List<string> { "abc" },
Crosshair = new XAxisCrosshair()
}
},
YAxis = new List<YAxis>
{
new YAxis
{
Title = new YAxisTitle { Text = "Relative Score" },
}
},
Tooltip = new Tooltip
{
Shared = true,
PointFormat = "<span style="color:{point.color}">u25CF</span> Score: <b>{point.y:.1f}</b><br/>"
},
PlotOptions = new PlotOptions
{
Column = new PlotOptionsColumn
{
Stacking = PlotOptionsColumnStacking.Normal,
Animation = new Animation
{
Duration = 2000,
Easing = "easeOutBounce"
}
}
},
Legend = new Legend
{
Enabled = false
}
};
1