Click here to Skip to main content
15,896,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Converting the application from using Chart FX 7 to 8. Crosstabdataprovider is obsolete now. After changing the code to use Pivoting (now available in chart fx 8) the application runs fine initially however if you click a button on the windows form to render the chart with different values the following error comes up.

"Value cannot be null. Parameter name: font"

An unhandled exception of type 'System.ArgumentNullException' occurred in System.Drawing.dll

Additional information: Value cannot be null.


New Code:
C#
Dim listProvider As New ListProvider(dataSource)

chart.DataSource = listProvider

Dim FieldName As New NumericDataField()
FieldName.DataPath = Me.SelectedValueType.FieldName
chart.DataSourceSettings.DataFields.Add(FieldName)

Dim XAxisFieldName As New NumericDataField()
XAxisFieldName.DataPath = formConfiguration.XAxisFieldName
chart.DataSourceSettings.DataFields.Add(XAxisFieldName)

chart.Series(0).Text = formConfiguration.SeriesControllingListBox.SelectedValue.ToString()


Old Code:
C#
Dim SeriesFieldName As New NumericDataField()
SeriesFieldName.DataPath = formConfiguration.SeriesFieldName
chart.DataSourceSettings.DataFields.Add(SeriesFieldName)

Dim adt As New AnalysisDataTransformer()
adt.Pivoting.Add(XAxisFieldName)

chart.DataSourceSettings.Transformers.Add(adt)

Dim listProvider As New ListProvider(dataSource)
Dim crosstabProvider As New CrosstabDataProvider With {.DataSource = listProvider}
With chart.DataSourceSettings.Fields
     .Add(New FieldMap(formConfiguration.SeriesFieldName, FieldUsage.ColumnHeading))
     .Add(New FieldMap(formConfiguration.XAxisFieldName, FieldUsage.RowHeading))
     .Add(New FieldMap(Me.SelectedValueType.FieldName, FieldUsage.Value))
End With

chart.DataSource = crosstabProvider
Posted
Updated 10-Jan-18 20:36pm
v2
Comments
Fredrik Bornander 12-May-14 9:12am    
Where is that exception being thrown? What line?
civic060 12-May-14 9:20am    
In the exception handler class (see below). <br>
 <br>

Public Function HandleException(ByVal e As Exception, ByVal handlingInstanceId As Guid) As Exception Implements IExceptionHandler.HandleException

Dim result As DialogResult = Me.ShowThreadExceptionDialog(e, handlingInstanceId)

Return e

End Function

Private Function ShowThreadExceptionDialog(ByVal e As Exception, ByVal handlingInstanceId As Guid) As DialogResult<br>
 <br>
'Format the exception<br>
Dim sb As StringBuilder = New StringBuilder<br>
Dim writer As StringWriter = New StringWriter(sb)<br>
Dim formatter As AppTextExceptionFormatter = New AppTextExceptionFormatter(writer, e, handlingInstanceId)<br>
formatter.Format()<br>
 <br>
Dim errorMsg As String = sb.ToString()<br>
 <br>
With My.Application.Info<br>
Return MessageBox.Show(errorMsg, String.Format("{0} Error - v{1}.{2}.{3}.{4}", .Title, .Version.Major, .Version.Minor, .Version.Build, .Version.Revision), MessageBoxButtons.OK, MessageBoxIcon.Information)<br>
End With<br>
 <br>
End Function
Fredrik Bornander 12-May-14 9:21am    
Are you sure it's being thrown from in there? Is that not just where it's being displayed?
Look at the stack trace of the exception and figure out the line from that, or turn on "break on exceptions".
civic060 12-May-14 9:43am    
Turning on break on exceptions also breaks the code above when it is trying to format and display the error. System.Drawing was not in my window so had to add that and turn on thrown for exceptions.

This is what the stack trace looks like.

at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea)
at System.Drawing.Graphics.MeasureString(String text, Font font)
at SoftwareFX.WinForms.Internal.GraphicsEx.MeasureString(String s, Font font, Int32 maxWidth, Boolean useCharacterRanges)
at ChartFX.WinForms.Title.a(IGraphicsEx A_0, Boolean A_1)
at ChartFX.WinForms.Title.a(g A_0, Rectangle[] A_1, Rectangle& A_2, Boolean A_3, HighlightState A_4)
at ChartFX.WinForms.TitleCollection.b(g A_0, Rectangle[] A_1)
at ChartFX.WinForms.g.b(Boolean A_0, Boolean A_1)
at ChartFX.WinForms.g.k()
at ChartFX.WinForms.Chart.a(PaintBar A_0, IGraphicsEx A_1, Rectangle A_2)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900