iT邦幫忙

0

請教asp.net的chart圖表繪圖時,想將x軸座標以每月1日標註的方法,若x軸的座標是日期轉成字串的連續座標點(營業日才有資料)?謝謝!

請教asp.net的chart圖表繪圖時,想將x軸座標以每月1日標註的方法,若x軸的座標是日期轉成字串的連續座標點(營業日才有資料)?或可自行設定是按每月第1日、每季第1日或是每年第1日在x軸顯示座標標籤,code如下,謝謝!

'Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.Interval = 10 '註解行,因不是每日都有,故不會都標註在每月1日
'Chart1.ChartAreas("ChartArea1").AxisX.Interval = 10 '註解行,因不是每日都有,故不會都標註在每月1日

    Chart1.ChartAreas("ChartArea1").AxisX.Title = "DATE"
    'Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Interval = 10
    Chart1.ChartAreas("ChartArea1").AxisY.Minimum = 25.0
    Chart1.ChartAreas("ChartArea1").AxisY.Interval = 2.5
    Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Format = "{0:00.0}"
    Chart1.ChartAreas("ChartArea1").AxisY.Title = "USD/barrel"
    '
    Chart1.Series.Add("Dated_Brent")
    Chart1.Series("Dated_Brent").ChartType = DataVisualization.Charting.SeriesChartType.Line
    Chart1.Series("Dated_Brent").Color = Drawing.Color.Red
    'Chart1.Series("Dated_Brent").MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
    Chart1.Legends.Add("Dated_Brent")
    Chart1.Legends("Dated_Brent").Docking = DataVisualization.Charting.Docking.Bottom
    Chart1.Legends("Dated_Brent").Alignment = Drawing.StringAlignment.Center
    Chart1.Legends("Dated_Brent").BorderColor = Drawing.Color.Maroon
    Chart1.Series("Dated_Brent").IsVisibleInLegend = True
    '
    Chart1.Series.Add("WTI_Cushing")
    Chart1.Series("WTI_Cushing").ChartType = DataVisualization.Charting.SeriesChartType.Line
    Chart1.Series("WTI_Cushing").Color = Drawing.Color.Blue
    'Chart1.Series("WTI_Cushing").MarkerStyle = DataVisualization.Charting.MarkerStyle.Circle
    Chart1.Legends.Add("WTI_Cushing")
    Chart1.Series("WTI_Cushing").IsVisibleInLegend = True

    Dim Conn As SqlConnection = New SqlConnection

    Dim settings As ConnectionStringSettings
    settings = ConfigurationManager.ConnectionStrings("fbcnrCon")
    Conn = New SqlConnection(settings.ConnectionString)
    If Conn.State = 0 Then Conn.Open()
    Dim cmd As New SqlCommand
    Dim dr As SqlDataReader
    cmd.Connection = Conn
    cmd.CommandText = "SELECT Dated_Brent_date,Dated_Brent,WTI_Cushing FROM metal WHERE Dated_Brent_date>=DATEADD(year,-3, getdate()) ORDER BY Dated_Brent_date"
    dr = cmd.ExecuteReader
    While dr.Read


        Chart1.Series("Dated_Brent").Points.AddXY(Format(dr("Dated_Brent_date"), "yyyy-MM-dd").ToString, dr(1).ToString)

        Chart1.Series("WTI_Cushing").Points.AddXY(Format(dr("Dated_Brent_date"), "yyyy-MM-dd").ToString, dr(2).ToString)

    End While

    Chart1.Series("Dated_Brent").ToolTip = "Dated_Brent:(#VALX,#VALY)"
    Chart1.Series("WTI_Cushing").ToolTip = "WTI_Cushing:(#VALX,#VALY)"

    Conn.Close()
    Conn.Dispose()
tienliu iT邦新手 5 級 ‧ 2017-12-12 09:50:38 檢舉
測試原日期為字串格式改成日期格式,配合.AxisX.IntervalAutoMode、.AxisX.IntervalType及.AxisX.IntervalOffsetType參數調整,即可達成初步期待了。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答