Search code examples
c#asp.net.net-4.0highchartsdotnethighcharts

DotNet.Highcharts Error when using StackLabels


I have been trying out the dotnethighcharts library to make some graphs. I have managed to make a few graphs, but when I try to make graphs with StackLabels, I get this error: "System.NullReferenceException: Object reference not set to an instance of an object".

What is wrong in my code or is this a bug in DotNet.Highchart? Am i missing something?

Any information at all is appreciated.

Thanks in advance.

Here is my code:

        Series serie1 = new Series { Name = "Person1", Stack = "1", Data = new Data(Fetch_Value1Data_From_GoalData()) };
        Series serie2 = new Series { Name = "Person2", Stack = "1", Data = new Data(Fetch_Value1Data_From_GoalData()) };
        Series serie3 = new Series { Name = "Person3", Stack = "2", Data = new Data(Fetch_Value1Data_From_GoalData()) };
        Series serie4 = new Series { Name = "Person4", Stack = "2", Data = new Data(Fetch_Value1Data_From_GoalData()) };

        Highcharts chart2 = new Highcharts("Chart2")
        .InitChart(new Chart { Height = 300, Width = 400, Type = ChartTypes.Column })
        .SetYAxis(new YAxis { StackLabels = { Enabled = true } })
        .SetSeries(new Series[] { serie1, serie2, serie3, serie4 })
        .SetPlotOptions(new PlotOptions
        {

            Column = new PlotOptionsColumn
            {
                Stacking = Stackings.Normal,
            }
        });

        ltrChart1.Text = chart2.ToHtmlString();

Solution

  • I solved it myself. All I was missing was to make a new YAxisStackLabels

    Here is the code for SetYAxis:

                    .SetYAxis(new YAxis 
                    {               
                        StackLabels = new YAxisStackLabels 
                        { 
                            Enabled = true, Style = @"fontWeight: 'bold', color: 'black'" 
                        } 
                    })