From: SourceForge.net <no...@so...> - 2009-10-18 02:26:06
|
Bugs item #2881142, was opened at 2009-10-18 02:26 Message generated for change (Tracker Item Submitted) made by nobody You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=821568&aid=2881142&group_id=161868 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None Status: Open Resolution: None Priority: 5 Private: Yes Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: runtime error, created when using 2nd y axis label Initial Comment: 'runtime error, created when using 2nd y axis label 'i.e. plotSurfaceBalance.YAxis2.Label = "test" 'causes runtime error! Imports NPlot Public Class Form1 ' The NPlot download file contains a lot of examples as to how to use the 'NPlot charting library. Give it a try if you are looking for more examples! 'For this example you need to include the NPlot namespace. 'To do this, at the top of your class file write 'imports NPlot;'. 'To make this example work, you need to add two plot surface controls to your form. 'These controls should be named plotSurfaceBalance and plotSurfacePercent. 'Tip: Set the DateTimeToolTip property for each control to true. 'The actual code: 'Dim instance As PrintForm Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' plotSurfaceBalance.Clear() plotSurfacePercent.Clear() ''Add a background grid for better chart readability. Dim grid As Grid = New Grid() Grid.VerticalGridType = Grid.GridType.Coarse Grid.HorizontalGridType = Grid.GridType.Coarse Grid.MajorGridPen = New Pen(Color.LightGray, 1.0F) plotSurfaceBalance.Add(grid) plotSurfacePercent.Add(Grid) '' //Create a step plot instance for the balance chart. Dim stepBalance As LinePlot = New LinePlot() stepBalance.Pen = New Pen(Color.Red, 2) '' //Create a step plot instance for the balance chart. Dim stepBalance2 As LinePlot = New LinePlot() stepBalance2.Pen = New Pen(Color.Blue, 2) '' //Create a bar plot instance for the percent chart. Dim barPercent As BarPlot = New BarPlot() barPercent.FillBrush = NPlot.RectangleBrushes.Solid.Green '' //Create the lists from which to pull data. Dim balanceAxis As List(Of DateTime) = New List(Of DateTime) Dim percentAxis As List(Of DateTime) = New List(Of DateTime) Dim balanceAmount As List(Of Decimal) = New List(Of Decimal)() Dim balance2Amount As List(Of Decimal) = New List(Of Decimal)() Dim percentAmount As List(Of Decimal) = New List(Of Decimal)() '' //The following code populates the lists above with data. '' //This code is intended as an example. You could use other '' //data sources such as a database to populate the lists. Dim startDate As DateTime = New DateTime(2000, 1, 1) Dim balanceValues As Decimal() = New Decimal() { _ 500.0, 503.0, 499.3, 489.6, 489.3, 483.3, 480.0, 475.1, _ 476.2, 476.2, 480.1, 495.3, 499.3, 497.7, 500.1, 510.45, _ 515.3, 520.8, 525.3, 521.3, 522.67, 519.8, 524.3, 530.01, _ 529.55, 527.1, 535.66, 539.21, 540.06, 540.0} 'new CHM Dim balance2Values As Decimal() = New Decimal() { _ 510.0, 403.0, 459.3, 389.6, 469.3, 443.3, 580.0, 375.1, _ 466.2, 476.2, 460.1, 455.3, 469.3, 417.7, 508.1, 517.45, _ 517.3, 540.8, 625.3, 571.3, 552.67, 559.8, 574.3, 570.01, _ 519.55, 527.1, 505.66, 539.21, 500.06, 500.0} '' //Add data to X axis datetime lists. For i As Integer = 0 To 30 '' //The percent date is offset by half a period to make the charts '' //visually correspond when plotted. balanceAxis.Add(startDate.AddDays(i)) percentAxis.Add(startDate.AddDays(i + 0.5)) Next ''//Populate the balanceAmount list. For Each value As Decimal In balanceValues balanceAmount.Add(value) Next 'new CHM ''//Populate the balance2Amount list. For Each value As Decimal In balance2Values balance2Amount.Add(value) Next '' //Calculate the percentage return (first period cannot be computed). percentAmount.Add(0) For i As Integer = 0 To balanceAmount.Count - 2 percentAmount.Add((balanceAmount(i + 1) - balanceAmount(i)) / balanceAmount(i) * 100) Next '' //#NPLot 9.10.0 cannot plot negative top bars. Future releases will '' //#be capable of doing this and will also add a property to set the '' //#bottom value to a fixed value for each bar.(OrdinateDataBottomAll) '' //#for now you can do this yourself. Dim top As List(Of Decimal) = New List(Of Decimal) Dim bottom As List(Of Decimal) = New List(Of Decimal) For Each value As Decimal In percentAmount If (value >= 0) Then top.Add(value) bottom.Add(0) Else top.Add(0) bottom.Add(value) End If Next ''//Set the datasource and the xax for the balance plot. stepBalance.AbscissaData = balanceAxis stepBalance.DataSource = balanceAmount 'add x,y pair stepBalance2.AbscissaData = balanceAxis stepBalance2.DataSource = balance2Amount '' //Set the datasource and the xax for the percent plot. barPercent.AbscissaData = percentAxis barPercent.OrdinateDataBottom = bottom barPercent.OrdinateDataTop = top '' //Add stepBalance to plotSurfaceBalance. plotSurfaceBalance.Add(stepBalance) plotSurfaceBalance.Add(stepBalance2) '' //Balance plot general settings. plotSurfaceBalance.ShowCoordinates = True plotSurfaceBalance.YAxis1.Label = "Balance - EURO" 'plotSurfaceBalance.YAxis2.Label = "test" plotSurfaceBalance.YAxis1.LabelOffsetAbsolute = True plotSurfaceBalance.YAxis1.LabelOffset = 40 plotSurfaceBalance.YAxis1.LabelColor = Color.Crimson plotSurfaceBalance.XAxis1.HideTickText = False plotSurfaceBalance.XAxis1.LabelColor = Color.Red plotSurfaceBalance.Padding = 5 'plotSurfaceBalance.YAxis2.Label = "test" 'causes runtime error! 'plotSurfaceBalance.YAxis2.LabelOffsetAbsolute = True 'plotSurfaceBalance.YAxis2.LabelOffset = 60 'plotSurfaceBalance.XAxis2.HideTickText = True ''//Add barPercent to plotSurfacePercent. plotSurfacePercent.Add(barPercent) '' //Percent plot surface general settings. plotSurfacePercent.ShowCoordinates = True plotSurfacePercent.YAxis1.Label = "Percentage Return" plotSurfacePercent.YAxis1.LabelOffsetAbsolute = True plotSurfacePercent.YAxis1.LabelOffset = 40 plotSurfacePercent.YAxis1.LabelColor = Color.DarkMagenta plotSurfacePercent.Padding = 5 '' //Align percent plot axes. Dim ax As DateTimeAxis = New DateTimeAxis(plotSurfaceBalance.XAxis1) ax.HideTickText = False plotSurfacePercent.XAxis1 = ax ' '' //Align percent plot axes. 'Dim ax2 As DateTimeAxis = New DateTimeAxis(plotSurfaceBalance.XAxis2) 'ax2.HideTickText = False 'plotSurfacePercent.XAxis1 = ax2 '' //Refresh surfaces. plotSurfaceBalance.Refresh() plotSurfacePercent.Refresh() End Sub Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click 'Dim pf1 As New PrintForm pf.Form = Me pf.PrintAction = Printing.PrintAction.PrintToPreview pf.Print() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub End Class ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=821568&aid=2881142&group_id=161868 |