Chart: Show more value descriptions on X-Axis

后端 未结 2 2070
春和景丽
春和景丽 2021-01-08 00:02

I\'m showing a Chart to the user which has one chart area with a line chart. On this, I got, for example, one line. This line has about 200 values. Those values do all have

2条回答
  •  灰色年华
    2021-01-08 00:44

    I think you should convert the string date representation to an actual datetime object before adding it to the chart. I didn't test it but something like this: (where yourDate is the string you used to pass to the chart)

    Dim format as String = "MM.dd.yyyy"
    Dim actualDate as Date = Date.ParseExact(yourDate, format)
    chart.Series(chart.Series.Count - 1).Points.AddXY(actualDate, 4.9)
    

    The chart can manage datetime object instead of strings and it has special code that deals with dates. If you do this you you can adjust how it is displayed by formatting:

    chart.ChartAreas(0).AxisX.LabelStyle.Format ="MM.dd.yyyy"
    chart.ChartAreas(0).AxisX.Interval = 1
    chart.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days
    

    If you wanted to only display every other day change the interval to 2

提交回复
热议问题