gpt4 book ai didi

vb.net - 图表 : Show more value descriptions on X-Axis

转载 作者:行者123 更新时间:2023-12-03 14:45:42 24 4
gpt4 key购买 nike

我正在向用户显示一个图表,其中有一个带有折线图的图表区域。例如,在这一点上,我得到了一行。该行有大约 200 个值。这些值都有描述(例如 "01.01.2013""05.02.2013" 等等)。

显示图表时,我只能看到两个描述,即使会有更多描述的空间。该线显示正确,但只描述了两点。

我垂直旋转了文本,因此有更多空间,但这没有帮助。如果我显示较少的值(5 或 10),说明会正确显示。

这就是它的实际外观(描述实际上是字符串,而不是日期)。

The Graph with a lot of values but only two descriptions at the X axis

感谢您的帮助!

编辑 :我的代码:

chart.ChartAreas(0).AxisY.Maximum = 6
chart.ChartAreas(0).AxisY.Minimum = 1
chart.ChartAreas(0).AxisX.LabelStyle.Angle = -90
chart.Series.Clear()
chart.ChartAreas(0).AxisY.StripLines.Clear()
Dim myStripLine1 as new StripLine()
myStripLine1.IntervalOffset = 4
chart.ChartAreas(0).AxisY.StripLines.add(myStripLine1)

'now adding all series
chart.Series.Add("Chemie") 'just to take the example in the image above
chart.Series(chart.Series.Count - 1).ChartType = DataVisualization.Charting.SeriesChartType.Line
chart.Series(chart.Series.Count - 1).BorderWidth = 4

'now adding quite much values (on every date, every Serie has a value)
chart.Series(chart.Series.Count - 1).Points.AddXY("01.03.2011", 4.9)

在每个日期,都会为所有系列输入一个新点,但只有那些具有重要值的点才会突出显示。之间的那些值是通过数学计算得出的。

一个例子来解释这个:我有两个系列,一个在点 "01.01.2013" 上有两个值(6 和 4)和 "03.01.2013" .另一个系列在 "01.01.2013" 上有 3 个值 (4,6,5.5) , "02.01.2013""03.01.2013" .当我只显示它们时,第一个系列将在第二个日期结束,即使第三个日期有一个值。我通过在日期为 "02.01.2013" 的第一个系列中填充一个虚拟值来解决这个问题。这只是此时的平均值 (=5)。这一点根本不会用标记项目符号突出显示。这就是我绘制图形的方式。

编辑2:

Skippy's 回答和评论,我的新审判。变量 MainForm.gradesDictionary(Of Integer,Dictionary(Of String, String))其中包含大约 150 个等级
    Dim subjects As New Dictionary(Of Integer, ArrayList)
Dim allgrades As New ArrayList
For Each grade In MainForm.grades
Dim cD As New Dictionary(Of String, String)
cD.Add("SUBJECTID", grade.Value("SUBJECTID"))
cD.Add("GRADE", grade.Value("GRADE"))
cD.Add("DATE", grade.Value("DATE"))
allgrades.Add(cD)
Next

cht_main.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days
cht_main.ChartAreas(0).AxisX.LabelStyle.Angle = -90
Dim gradesDateSorter = New gradesDateSorter()
allgrades.Sort(gradesDateSorter)
For Each grade In allgrades
If Not subjects.ContainsKey(Integer.Parse(grade("SUBJECTID"))) Then
subjects.Add(Integer.Parse(grade("SUBJECTID")), New ArrayList)
End If
Dim gradeDict As New Dictionary(Of String, String)
gradeDict.Add("DATE", grade("DATE"))
gradeDict.Add("GRADE", grade("GRADE"))
subjects(Integer.Parse(grade("SUBJECTID"))).Add(gradeDict)
Next
For Each subject In subjects
'adding serie
cht_main.Series.Add(MainForm.subjects(subject.Key)("NAME"))
cht_main.Series(cht_main.Series.Count - 1).ChartType = DataVisualization.Charting.SeriesChartType.Line
cht_main.Series(cht_main.Series.Count - 1).BorderWidth = 4
'cht_main.Series(cht_main.Series.Count - 1).IsXValueIndexed = True
For Each grade In subject.Value
cht_main.Series(cht_main.Series.Count - 1).Points.AddXY(Date.Parse(grade("DATE")), Double.Parse(grade("GRADE")))
Next
Next

在倒数第 5 行,我评论了 IsXValueIndexed=True因为当我激活它时,图表会生成一个大的红色错误十字。

解决方案

在 X 轴上设置间隔就行了!
chart.ChartAreas(0).AxisX.Interval = 1

来自 Skippy 的解决方案

最佳答案

是的,我同意迈克尔的看法。我现在只能补充说明。

通过设置您的间隔:

myStripLine1.IntervalOffset = 4

您保证您的 X 轴值将仅以 4 个“通用 x 轴”值的频率绘制:

将此设置为 vale 为 1 将为每个 x 轴值提供一个值,即作为整数递增(在这种情况下为天)
chart.ChartAreas(0).AxisX.Interval = 1

并声明要键入的 x 轴值:
DateTimeIntervalType.Days

'Declaration
Public Sub Add( _
labelsStep As Double, _
intervalType As DateTimeIntervalType, _
format As String _
)
End Sub

chart.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days

'which as shown in Michael's answer is parsed to string.

Dim format as String = "MM.dd.yyyy"
Dim actualDate as Date = Date.ParseExact(yourDate, format)

正如迈克尔在他的评论中提到的。
通过设置
mySeries.XValueIndexed = True

将绘制每个索引的 X 轴值。

如以下引用中所述,并提供了链接。

Each data point in a series has X and Y values that determine its position in the plotting area. With some charts, the X value of points is not important, and does not have to be provided. In this case, the point positions in the plotting area are determined only by their point index (i.e. their location in the Points collection) and their Y values.

When X values are "indexed", the data point index, not a point's X value, is used to determine the position of points along the categorical (X) axis. For example in Figure 1 below, two charts are shown displaying the same data. However, the first chart uses non-indexed X values, therefore the X values of those points determine their location along the x-axis. The second chart is indexed, therefore its point indices are used to determine their position along the x-axis. In this case the X values are only used for the axis labels, and nothing more.



http://support2.dundas.com/onlinedocumentation/winchart2005/Data_IndexedXValues.html

我在以下站点获取了有关间隔和间隔偏移的原始信息:

http://support2.dundas.com/Default.aspx?article=705

此处讨论了数据类型并解决了突出显示值的问题。

On every date, a new point gets entered for all series, but only those points where they have important values get highlighted

For example, assume you wish to create a re-occurring StripLine to highlight weekends. You set the interval to 7 and its type to Days. Since the first point is Sunday you set the IntervalOffset to 6 (to mean the 6th day of the week) and its type to Days. The resulting chart does not show the first StripLine.



这是设置间隔的说明。

A good rule of thumb to follow when using the Interval and IntervalOffset properties of the Chart is that the IntervalOffset should be a lower interval magnitude than the Interval (ie. Interval Days / IntervalOffset Hours, Interval Years / IntervalOffset Months, etc.).



我添加了这些来源:
  • 供您引用
  • 为了表明我也在确定问题后进行了研究,如我上面的评论所述。

  • Florian, can you pls show the code for the labels, properties etc of the x-axis? – yvytty yesterday

    Did you ever consider 3rd party plotting components, such as ZedGraph ? Most likely such little caveats are already covered there. Give it a shot! – Neolisk yesterday



    针对 ZedGraph 我建议:

    并且:查看您的代码后

    Hi can I clarify, you WANT to plot values daily? I think I have your solution, just need clarification, you have all the tools within vb.net

    @yvytty, nope, the dates do not have to be daily, there can also be no value for a long time and I don't want a big span in my chart where no data is. Actually, I could also write some sample text at the X axis values, the dates are only confusing. The main problem is that the VB chart somehow calculates a very big margin on those descriptions at the X axis



    它并不表明您已格式化日期和日期字符串。还需要考虑的是,您没有使用 en-US 日期格式(我在澳大利亚,所以我们的格式与您相同)。默认日期类型为 en-US。

    请引用 DateTime.ParseExact方法

    http://msdn.microsoft.com/en-us/library/system.datetime.parseexact.aspx

    我从 MSDN 中获取了片段。
     Dim dateString, format As String   
    Dim result As Date
    Dim provider As CultureInfo = CultureInfo.InvariantCulture

    Parse date and time with custom specifier.
    dateString = "Sun 15 Jun 2008 8:30 AM -06:00"
    format = "ddd dd MMM yyyy h:mm tt zzz"
    result = Date.ParseExact(dateString, format, provider)

    见链接:
    http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx

    The DateTime.ToString(IFormatProvider) method returns the string representation of a date and time value using the short date and long time pattern of a specific culture. The following example uses the DateTime.ToString(IFormatProvider) method to display the date and time using the short date and long time pattern for the fr-FR culture.


    Dim date1 As Date = #3/1/2008 7:00AM#
    Console.WriteLine(date1.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR")))
    ' Displays 01/03/2008 07:00:00

    请看这个链接:
    http://msdn.microsoft.com/en-us/library/system.datetime.aspx

    所以它应该是这样的:
    'note
    Imports System.Globalization

    Dim format as String = "dd.MM.yyyy"
    Dim actualDate as Date = Date.ParseExact(yourDate, format, provider)

    chart.ChartAreas(0).AxisX.LabelStyle.Format ="dd.MM.yyyy"

    cht_main.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days

    cht_main.ChartAreas(0).AxisX.Interval = 1

    还:
    Double.Parse(grade("GRADE")
    'grade is not of type double

    关于vb.net - 图表 : Show more value descriptions on X-Axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16708974/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com