在烛台图表中更改蜡烛的颜色

时间:2014-10-28 12:01:21

标签: vb.net colors charts candlestick-chart

无论我尝试过什么,我都无法改变这些颜色。

图表中的点数是从DGV添加的:

 For Count As Integer = 1 To rowC
            Chart1.Series(0).Points.AddXY(DGVH1.Item(0, Count).Value, DGVH1.Item(2, Count).Value, DGVH1.Item(3, Count).Value, DGVH1.Item(1, Count).Value, DGVH1.Item(4, Count).Value)
        Next

我可以为所有蜡烛和灯芯设置color2和border颜色:

 With Chart1.Series(0)
   .BorderColor = Color.DimGray
   .Color = Color.DimGray

,结果如下: enter image description here

...但是当color2改变时,也无法改变color1(第一张图片中的白色):

   For i As Integer = 0 To rowC - 1 'row count
        If DGVH1.Rows(i + 1).Cells(1).Value < DGVH1.Rows(i + 1).Cells(4).Value Then
                           Chart1.Series(0).Points(i).Color = Color.Tomato
        End If
    Next

我明白了(灯芯颜色也发生了变化,将<更改为>,在上面的代码中,不会改变颜色1):

enter image description here

看起来非常可怕。如果有人愿意就如何解决这个问题给我一些指示...

由于

编辑1:烛台图表的数据来源

    DGVH1.Rows.Clear()
            DGVH1.Columns.Clear()
            Dim Today0 As Date = Date.Today
            Dim Day0 As Integer = Today0.Day
            Dim Month0 As Integer = Today0.Month - 1
            Dim Year0 As Integer = Today0.Year
            Dim Year10 As Integer = Today0.Year - 10

            Dim MonthFormat As String = "MMM"
            Dim MonthDate As String = (Today0.ToString(MonthFormat))

            Dim myUri As New Uri("http://www.google.com/finance/historical?q=" & "AAPL" & "&startdate=" & MonthDate & "+" & Day0 & "%2C+" & Year10 & "&enddate=" & MonthDate & "+" & Day0 & "%2C+" & Year0 & "&num=30&ei=Ge5HVOGtEOaZwQPewYCoBQ=csv&output=csv")
            Dim request As HttpWebRequest = DirectCast(WebRequest.Create(myUri), HttpWebRequest)
            Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            Dim receiveStream As Stream = response.GetResponseStream()

            Dim TextFieldParser1 As New Microsoft.VisualBasic.FileIO.TextFieldParser(receiveStream)
            'Dim TextFieldParser1 As New Microsoft.VisualBasic.FileIO.TextFieldParser("c:\AAPL Balance SheetA.csv")
            TextFieldParser1.Delimiters = New String() {","}
            While Not TextFieldParser1.EndOfData
                Dim Row1 As String() = TextFieldParser1.ReadFields()

                If DGVH1.Columns.Count = 0 AndAlso Row1.Count > 0 Then
                    Dim i As Integer

                    For i = 0 To 5
                        DGVH1.Columns.Add("Column" & i + 1, "Column" & i + 1)
                    Next
                End If

                DGVH1.Rows.Add(Row1)
            End While

            receiveStream.Close()
            response.Close()

'code below converts everything to numbers...some random values are not numerical (strings) 

            For i As Integer = 1 To DGVH1.RowCount - 2
                DGVH1.Rows(i).Cells(1).Value = DGVH1.Rows(i).Cells(1).Value + 0
                DGVH1.Rows(i).Cells(2).Value = DGVH1.Rows(i).Cells(2).Value + 0
                DGVH1.Rows(i).Cells(3).Value = DGVH1.Rows(i).Cells(3).Value + 0
                DGVH1.Rows(i).Cells(4).Value = DGVH1.Rows(i).Cells(4).Value + 0
                    DGVH1.Rows(i).Cells(5).Value = DGVH1.Rows(i).Cells(5).Value + 0
next

编辑2:烛台图表代码

Dim rowC As Integer = 50 'DGVH1.RowCount - 2

    With TAChart1
        .Legends.Clear()
        .Series.Clear()
    End With
TAChart1.Series.Add("Open")
TAChart1.Series(0).ChartType = SeriesChartType.Candlestick


Dim Max1 As Long = 0
For i As Integer = 1 To rowC
    If Max1 < DGVH1.Rows(i).Cells(2).Value Then
        Max1 = DGVH1.Rows(i).Cells(2).Value
    End If
Next

Dim Min1 As Long = Max1
For i As Integer = 1 To rowC
    If Min1 > DGVH1.Rows(i).Cells(3).Value Then Min1 = DGVH1.Rows(i).Cells(3).Value
Next

Max1 = Max1 * 0.01 + Max1
Min1 = Min1 - Min1 * 0.01


For Count As Integer = 1 To rowC
    TAChart1.Series(0).Points.AddXY(DGVH1.Item(0, Count).Value, DGVH1.Item(2, Count).Value, DGVH1.Item(3, Count).Value, DGVH1.Item(1, Count).Value, DGVH1.Item(4, Count).Value)
Next

TAChart1.BackColor = Color.FromArgb(25, 25, 25)

With TAChart1.ChartAreas(0)
    .AxisY.Minimum = Min1
    .AxisY.Maximum = Max1
    .AxisY2.Minimum = Min1
    .AxisY2.Maximum = Max1
    .AxisX.MajorGrid.Enabled = False
    .AxisY.MajorGrid.LineColor = Color.FromArgb(45, 45, 45)
    .AxisY2.MajorGrid.LineWidth = 0
    .AxisX.IsReversed = True
    .BackColor = Color.FromArgb(25, 25, 25)
    .AxisX.LineWidth = 0
    .AxisY.LineWidth = 0
    .AxisY2.LineWidth = 0
    .AxisX.LabelStyle.ForeColor = Color.Gainsboro
    .AxisX.LabelStyle.Font = New Font("Cambria", 8, FontStyle.Regular)
    .AxisY.LabelStyle.Enabled = False
    .AxisY2.LabelStyle.Enabled = False
    .AxisX.MajorTickMark.Enabled = False
    .AxisY.MajorTickMark.Enabled = False
    .AxisY2.MajorTickMark.Enabled = False
    .AxisX.MinorTickMark.Enabled = False
    .AxisY.MinorTickMark.Enabled = False
    .AxisY2.MinorTickMark.Enabled = False
    .AxisX.LabelStyle.Angle = 40
    .AxisX.Interval = 5
End With

With TAChart1.Series(0)
    .BorderColor = Color.DimGray
    ' .Color = Color.Tomato
End With

For i As Integer = 0 To rowC - 1
    If DGVH1.Rows(i + 1).Cells(1).Value > DGVH1.Rows(i + 1).Cells(4).Value Then
        TAChart1.Series(0).Points(i).BorderColor = Color.DimGray
        TAChart1.Series(0).Points(i).Color = Color.Green
        TAChart1.Series(0).Points(i).LabelForeColor = Color.Green
    End If
Next

For i As Integer = 0 To rowC - 1
    If DGVH1.Rows(i + 1).Cells(1).Value < DGVH1.Rows(i + 1).Cells(4).Value Then
        TAChart1.Series(0).Points(i).BorderColor = Color.DimGray
        TAChart1.Series(0).Points(i).Color = Color.Red
        TAChart1.Series(0).Points(i).LabelForeColor = Color.Red
    End If
Next

0 个答案:

没有答案