⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xchart.vb

📁 chart图片,统计,网上下来的源代码
💻 VB
📖 第 1 页 / 共 5 页
字号:
Option Strict Off
Option Explicit On
<System.Runtime.InteropServices.ProgId("XChart_NET.XChart")> Public Class XChart
	Inherits System.Windows.Forms.UserControl
	Public Event ChartTypeChange()
	Public Event ChartTitleColorChange()
	Public Event BarColorChange()
	Public Event MaxYChange()
	Public Event AxisLabelXColorChange()
	Public Event HotTrackingChange()
	Public Event ChartSubTitleColorChange()
	Public Event AxisItemsXColorChange()
	Public Event InfoBackColorChange()
	Public Event AxisItemsYColorChange()
	Public Event MajorGridColorChange()
	Public Event SelectedBarColorChange()
	Public Event InfoForeColorChange()
	Public Event MinYChange()
	Public Event LineColorChange()
	Public Event AxisLabelYColorChange()
	Public Event BackColorChange()
	Public Event CustomMenuItemsChange()
	
	Private Structure PointAPI 'API Point structure
		Dim X As Integer
		Dim Y As Integer
	End Structure
	
	Private Const PI As Double = 3.14159265358979
	Private Const RADS As Double = PI / 180 '<Degrees> * RADS = radians
	
	'UPGRADE_WARNING: 结构 PointAPI 可能要求封送处理属性作为此 Declare 语句中的参数传递。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"”
	Private Declare Function Polygon Lib "gdi32" (ByVal hDC As Integer, ByRef lpPoint As PointAPI, ByVal nCount As Integer) As Integer
	
	Private uColumns() As Double 'array of column height values
	'used to determine hittest feature.
	
	'--------------------------------------------------------------------------------
	Public Enum LegendPrintConstants 'the enumerated for legend printing
		legPrintNone = 0
		legPrintGraph
		legPrintText
	End Enum
	
	Private uLegendPrintMode As LegendPrintConstants
	
	Public Enum PrinterFitConstants 'the enumerated for printing
		prtFitCentered = 0
		prtFitStretched
		prtFitTopLeft
		prtFitTopRight
		prtFitBottomLeft
		prtFitBottomRight
	End Enum
	
	Private uPrinterFit As PrinterFitConstants
	'UPGRADE_ISSUE: PrinterObjectConstants 对象 未升级。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"”
    Private uPrinterOrientation As PrinterObjectConstants
	Private uDataFormat As String 'the data format for numeric values
	Private dblMeanValue As Double 'the mean value
	Private uMeanOn As Boolean 'marker indicating if the mean value must be displayed
	Private uMeanColor As Integer 'the mean line color
	Private Const MEAN_CAPTION As String = "Mean"
	Private uMeanCaption As String 'the mean caption used in the legend
	Private uPicture As System.Drawing.Image 'the background picture
	'(TRUE) or stretched (FALSE)
	Private uBarPicture As System.Drawing.Image 'the background picture
	'(shadow takes effect only if line width is 1!)
	Private uAutoRedraw As Boolean 'marker indicating if the chart is auto-redrawn
	'upon every property change
	Private uRangeY As Short 'the absolute range between Y-axis min. ad max. values
	Private uDataType As Short 'indicates the data distribution in the Y axis
	Private Const DT_BOTH As Short = 0 ' 0 = range(-Y0, +Y1)
	Private Const DT_NEG As Short = 1 ' 1 = range(-Y0, -Y1)
	Private Const DT_POS As Short = 2 ' 2 = range(+Y0, +Y1)
	
	Private uMinYValue As Double 'minimum y value
	Private uLineColor As Integer 'the color of the line
	Private uLineStyle As Short 'the line style
	Private uBarColor As Integer 'the backcolor of the bars
	Private uBarFillStyle As Short 'the bars fill style
	Private uSelectedBarColor As Integer 'the selected bar backcolor
	Private uMajorGridColor As Integer 'the major intersect grid color
	Private uMinorGridOn As Boolean 'marker indicating display of minor grid
	Private uMajorGridOn As Boolean 'marker indicating display of major grid
	Private uInfoBackColor As Integer 'the information box background color
	Private uInfoForeColor As Integer 'the information box foreground color
	Private uXAxisLabelColor As Integer 'the X axis label color
	Private uYAxisLabelColor As Integer 'the Y axis label color
	Private uXAxisItemsColor As Integer 'the X axis items color
	Private uYAxisItemsColor As Integer 'the Y axis items color
	Private uChartTitleColor As Integer 'the chart title color
	Private uChartSubTitleColor As Integer 'the chart subtitle color
	Private uSaveAsCaption As String 'the SaveAs dialog box caption
	Private uInfoItems As String 'the information items (to be displayed in the info box)
	Private Const INFO_ITEMS As String = "Value|Description|Mean"
	
	Public Enum ChartMenuConstants 'the enumerated for menu type
		xcPopUpMenu = 0
		xcButtonMenu
	End Enum
	
	Private uMenuItems As String 'the menu's items.
	Private Const MENU_ITEMS As String = "&Save as...|&Print|&Copy|Selection &information|&Legend|&Hide"
	
	Private uCustomMenuItems As String 'the custom menu's items.
	Private Const CUSTOM_MENU_ITEMS As Object = Nothing
	
	Private uLegendCaption As String 'the legend's tooltip string
	Private Const LEGEND_CAPTION As String = "Display legend"
	
	Private Const XC_BAR As Short = 1
	Private Const XC_SYMBOL As Short = 2
	Private Const XC_LINE As Short = 4
	Private Const XC_OVAL As Short = 8
	Private Const XC_TRIANGLE As Short = 16
	Private Const XC_RHOMBUS As Short = 32
	Private Const XC_TRAPEZIUM As Short = 64
	Public Enum ChartTypeConstants 'the enumerated for chart type
		xcBar = XC_BAR
		xcSymbol = XC_SYMBOL
		xcLine = XC_LINE
		xcBarLine = XC_BAR + XC_LINE
		xcSymbolLine = XC_SYMBOL + XC_LINE
		xcOval = XC_OVAL
		xcOvalLine = XC_OVAL + XC_LINE
		xcTriangle = XC_TRIANGLE
		xcTriangleLine = XC_TRIANGLE + XC_LINE
		xcRhombus = XC_RHOMBUS
		xcRhombusLine = XC_RHOMBUS + XC_LINE
		xcTrapezium = XC_TRAPEZIUM
		xcTrapeziumLine = XC_TRAPEZIUM + XC_LINE
	End Enum
	
	Private uChartType As ChartTypeConstants 'the chart type.
	Private uBarWidthPercentage As Short 'the column width (in percentage) just for bar type
	Private uLineWidth As Short 'the line width (used when uChartType=xcLine and for bar border in case of uChartType=xcBar)
	
	Private Const IDX_SAVE As Short = 0 'the command buttons' indexs
	Private Const IDX_PRINT As Short = 1
	Private Const IDX_COPY As Short = 2
	Private Const IDX_INFO As Short = 3
	Private Const IDX_LEGEND As Short = 4
	'--------------------------------------------------------------------------------
	
	Private uColWidth As Single 'the calculated width of each column
	Private uRowHeight As Single 'the calculated height of each column
	Private uTopMargin As Single '--------------------------------------
	Private uBottomMargin As Single 'margins used around the chart content
	Private uLeftMargin As Single '
	Private uRightMargin As Single
	Private uRightMarginOrg As Single '--------------------------------------
	Private uContentBorder As Boolean 'border around the chart content?
	Private uSelectable As Boolean 'marker indicating whether user can select a column
	Private uHotTracking As Boolean 'marker indicating use of hot tracking
	Private uSelectedColumn As Short 'marker indicating the selected column
	Private uOldSelection As Integer
	Private uDisplayDescript As Boolean 'display description when selectable
	Private uChartTitle As String 'chart title
	Private uChartSubTitle As String 'chart sub title
	Private uAxisXOn As Boolean 'marker indicating display of x axis
	Private uAxisYOn As Boolean 'marker indicating display of y axis
	Private uColorBars As Boolean 'marker indicating use of different coloured bars
	Private uIntersectMajor As Single 'major intersect value
	Private uIntersectMinor As Single 'minor intersect value
	Private uMaxYValue As Double 'maximum y value
	Private uXAxisLabel As String 'label to be displayed below the X-Axis
	Private uYAxisLabel As String 'label to be displayed left of the Y-Axis
	Private cItems As Collection 'collection of chart items
	
	Private offsetX As Integer
	Private offsetY As Integer
	
	Private bLegendAdded As Boolean
	Private bLegendClicked As Boolean
	Private bDisplayLegend As Boolean
	Private bResize As Boolean
	Private bResizeLegend As Boolean
	
	Private bProcessingOver As Boolean 'marker to speed up mouse over effects
	
	Public Structure ChartItem
		Dim ItemID As String
		Dim SelectedDescription As String
		Dim LegendDescription As String
		Dim XAxisDescription As String
		Dim Value As Double
	End Structure
	
	Public Event ItemClick(ByVal Sender As System.Object, ByVal e As ItemClickEventArgs)
	Public Event MenuItemClick(ByVal Sender As System.Object, ByVal e As MenuItemClickEventArgs)
	Public Shadows Event MouseDown(ByVal Sender As System.Object, ByVal e As MouseDownEventArgs)
	Public Shadows Event MouseUp(ByVal Sender As System.Object, ByVal e As MouseUpEventArgs)
	
	Public Function AddItem(ByRef cItem As ChartItem) As Boolean '5225522525
		Dim oChartItem As ChartItem
		cItems.Add(cItem)
		If uMeanOn = True Then
			
			'UPGRADE_WARNING: IsEmpty 已升级到 IsNothing 并具有新行为。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"”
			If IsNothing(uMeanCaption) Then uMeanCaption = MEAN_CAPTION
			With oChartItem
				.Value = dblMeanValue
				.ItemID = uMeanCaption
				.XAxisDescription = uMeanCaption
				.SelectedDescription = uMeanCaption
				.LegendDescription = uMeanCaption
			End With
			cItems.Add(oChartItem)
		End If
	End Function
	
	Private Sub DrawTrapezium(ByRef dblData As Double, ByRef sngX1 As Single, ByRef sngX2 As Single, ByRef sngY1 As Single, ByRef sngY2 As Single)
		
		On Error Resume Next
		
		Dim lRet As Integer
		Dim sngXTemp As Single
		Dim sngYTemp As Single
		Dim lngFillColor As Integer
		Dim uaPts(3) As PointAPI
		Dim intScaleMode As Short
		
		'the polygon function works only with pixels!
		'UPGRADE_ISSUE: UserControl 属性 UserControl.ScaleMode 未升级。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"”
		intScaleMode = MyBase.ScaleMode
		'UPGRADE_ISSUE: 常量 vbPixels 未升级。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="55B59875-9A95-4B71-9D6A-7C294BF7139D"”

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -