以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  生成的Histogram型图表上增加两条坚线  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=81436)

--  作者:漂亮美眉vszh
--  发布时间:2016/2/27 16:54:00
--  生成的Histogram型图表上增加两条坚线
生成的Histogram型图表上增加两条坚线,分别在最左边的0.1处和最右边的99处增加,每边一条

图片点击可在新窗口打开查看此主题相关图片如下:22.png
图片点击可在新窗口打开查看

Dim zz As WinForm.TextBox = e.Form.Controls("TextBox6")
Dim zxz As WinForm.TextBox = e.Form.Controls("TextBox8")
Dim zja As WinForm.Label = e.Form.Controls("Label03")
Dim zs As Double = zz.value
Dim zx As Double = zxz.value
Dim zj As Double = zja.text
MessageBox.Show(zs)
MessageBox.Show(zx)
MessageBox.Show(zj)
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Chart= Forms("直方图").Controls("Chart1") \' 引用窗口中的图表
Chart.ChartType = ChartTypeEnum.Histogram \' 设置图表类型
Chart.DataSource = "生成直方图表" \'设置绑定表
Chart.SeriesList.Clear() \'清除图表原来的图系
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Histogram.IntervalStart = zx \'指定起始值
Series.Histogram.IntervalWidth = zj \'指定分区宽度
Series.Histogram.IntervalNumber= zs \'指定分区个数
Series.Y.DataField = "数据" \'Y轴绑定到数量列

\'Dim Chart1 As WinForm.Chart \'定义一个图表变量
\'Dim Series1 As WinForm.ChartSeries \'定义一个图系变量
\'Chart1= Forms("直方图").Controls("Chart1") \' 引用窗口中的图表
\'Chart1.ChartType = ChartTypeEnum.Hilo \'设置图表类型
\'\'Chart.SeriesList.Clear() \'清除图表原来的图系
\'Series1 = Chart1.SeriesList.Add() \'增加一个图系
\'Series1.LineThickNess = 3 \'设置线条宽度
\'Series1.Length = 2 \'图系包括10个数据点
\'For i As Integer = 0 To 1 \'指定每个数据点的位置
    \'Series1.X(i) = i \'指定水平坐标
    \'Series1.Y(i) = 99 \'生成最大值
    \'Series1.Y1(i) = 0.1 \'生成最小值
\'Next
这是我写的代码,测试不成功,求老师们如何解决?

--  作者:大红袍
--  发布时间:2016/2/28 13:43:00
--  

辅助线的画法可以参考。

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=55270&skin=0

 


--  作者:漂亮美眉vszh
--  发布时间:2016/2/29 16:34:00
--  

 

柱状图_AfterLoad

 

\'

\'设定图表数据,因为只是演示,所以数据只用人工设置

\'

Dim a() As  Integer = {100,90,80,85,70,80,101,105,75,66,88,110} 

Dim i均值 As Integer = 87.5

Dim i上限 As Integer = 100

Dim i下限 As Integer = 80

\'

\'生成图表

\'

Dim i As Integer

Dim Chart As WinForm.Chart = e.Form.Controls("Chart1")

Dim C1Cha As C1.Win.C1Chart.C1Chart = Chart.BaseControl

Dim Series As WinForm.ChartSeries

Chart.VisualEffect = True

Chart.ChartType = ChartTypeEnum.Bar

Chart.SeriesList.Clear()

Series = Chart.SeriesList.Add()

Series.Length = 12

Series.Text = "金额"

For i = 0 To 11

    Series.X(i) = i

    Series.Y(i) = a(i)

    Chart.AxisX.SetValueLabel(i, i+1 & "月")

Next

Chart.AxisX.AnnoWithLabels = True

Chart.LegendVisible = True

Chart.LegendCompass= CompassEnum.South

 


--  作者:漂亮美眉vszh
--  发布时间:2016/2/29 16:34:00
--  

\'

\'增加均值

\'

Dim tl As C1.Win.C1Chart.TrendLine =  C1Cha.ChartGroups(0).ChartData.TrendsList.AddNewTrendLine()

tl.LineStyle.Color = Color.Gold    \'线条颜色

tl.LineStyle.Thickness = 2              \'线宽

tl.LineStyle.Pattern = 0   \'直线样式 0-5

Dim zxb = New zxb柱状图标辅助线()

zxb.SetXY(New PointF(-0.5,87.5),New PointF(11.5,87.5))

zxb.SetText("均线")

tl.CustomTrendLine = zxb

\'

\'增加下限

\'

tl  =  C1Cha.ChartGroups(0).ChartData.TrendsList.AddNewTrendLine()

tl.LineStyle.Color = Color.red   

tl.LineStyle.Thickness = 2             

tl.LineStyle.Pattern = 2  

zxb = New zxb柱状图标辅助线()

zxb.SetXY(New PointF(-0.5,80),New PointF(11.5,80))

zxb.SetText("下限")

tl.CustomTrendLine = zxb

 

\'

\'增加上限

\'

tl  =  C1Cha.ChartGroups(0).ChartData.TrendsList.AddNewTrendLine()

tl.LineStyle.Color = Color.BurlyWood   

tl.LineStyle.Thickness = 2             

tl.LineStyle.Pattern = 2

zxb = New zxb柱状图标辅助线()

zxb.SetXY(New PointF(-0.5,i上限),New PointF(11.5,i上限))

zxb.SetText("上限")

tl.CustomTrendLine = zxb

 

 


--  作者:漂亮美眉vszh
--  发布时间:2016/2/29 16:35:00
--  

图表辅助线

 

Public Class zxb柱状图标辅助线

    Implements C1.Win.C1Chart.ICustomTrendLine

 

    Private _x() As Double

    Private _y() As Double

 

    Public Sub Calculate(ByVal tl As C1.Win.C1Chart.TrendLine, ByVal x() As Double, ByVal y() As Double) Implements C1.Win.C1Chart.ICustomTrendLine.Calculate

 

        If x Is Nothing Or x.Length = 0 Or y Is Nothing Or y.Length = 0 Then

            _x = Nothing

            _y = Nothing

            Return

        End If

 

        _x = New Double(1) {}

        _y = New Double(1) {}

        _x(0) = _xy1.X

        _y(0) = _xy1.Y

        _x(1) = _xy2.X

        _y(1) = _xy2.Y

 

    End Sub

 

    Public Function GetXValues() As Double() Implements C1.Win.C1Chart.ICustomTrendLine.GetXValues

        Return _x

    End Function

 

    Public Function GetYValues() As Double() Implements C1.Win.C1Chart.ICustomTrendLine.GetYValues

        Return _y

    End Function

 

    Public Function GetY(ByVal x As Double) As Double Implements C1.Win.C1Chart.ICustomTrendLine.GetY

        Return 0

 

    End Function

 

    Public ReadOnly Property Text() As String Implements C1.Win.C1Chart.ICustomTrendLine.Text

        Get

            Return _text

        End Get

    End Property

 

    Private _xy1 As PointF = New PointF(0, 0)

    Private _xy2 As PointF = New PointF(0, 0)

    Public Sub SetXY(ByVal xy1 As PointF, ByVal xy2 As PointF)

        _xy1 = xy1

        _xy2 = xy2

    End Sub

 

    Private _text As String = ""

    Public Sub SetText(ByVal text As String)

        _text = text

    End Sub

End Class

 

谢谢老师的分享,我的线型是竖线,他的是横线,不知道改上面的哪句代码,自己试着翻译了一下,没找到哪句是趋势线方向,麻烦老师指点下,谢谢~~


--  作者:大红袍
--  发布时间:2016/2/29 16:37:00
--  

汗,这句代码的意思是设置两个点,你明白了吗?

 

zxb.SetXY(New PointF(-0.5,87.5), New PointF(11.5,87.5))