图表:在X轴上显示更多的值描述 [英] Chart: Show more value descriptions on X-Axis

查看:371
本文介绍了图表:在X轴上显示更多的值描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



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





感谢您的帮助!



:My Code:

  chart.ChartAreas(0).AxisY.Maximum = 6 
chart.ChartAreas .AxisY.Minimum = 1
chart.ChartAreas(0).AxisX.LabelStyle.Angle = -90
chart.Series.Clear()
chart.ChartAreas(0).AxisY.StripLines .Clear()
将myStripLine1作为新的StripLine()
myStripLine1.IntervalOffset = 4
chart.ChartAreas(0).AxisY.StripLines.add(myStripLine1)

'现在添加所有系列
chart.Series.Add(Chemie)'只是为了采取上面的图像示例
chart.Series(chart.Series.Count - 1).ChartType = DataVisualization .Charting.SeriesChartType.Line
chart.Series(chart.Series.Count - 1).BorderWidth = 4

'现在添加了很多值(在每个日期,每个系列都有一个值)
chart.Series(chart.SeriesCount - 1).Points.AddXY(01.03.2011,4.9)

在每个日期,对所有系列输入一个新点,但只有那些具有重要值的点被突出显示。



一个例子来解释这一点:我有两个系列,一个在点上有两个值(6和4) 01.01.2013​​03.01.2013​​。其他系列在01.01.2013​​02.01.2013​​和03.01.2013​​。当我只是显示它们时,第一个系列将在第二个日期结束,即使有第三个日期的值。我通过在第一个系列填充一个虚拟值来解决这个问题,日期02.01.2013​​这只是这一点的平均值(= 5)。这一点根本没有用标记项目符号突出显示。



href =http://stackoverflow.com/users/1082944/yvette> Skippy的回答和评论,我的新试用。变量 MainForm.grades 是一个 Dictionary(Of Integer,Dictionary(Of String,String))成绩

 昏暗主题作为新字典(Integer,ArrayList)
Dim allgrades As New ArrayList
每个等级在MainForm.grades
Dim cD作为新字典(字符串,字符串)
cD.Add(SUBJECTID,grade.Value(SUBJECTID))
cD.Add GRADE,grade.Value(GRADE))
cD.Add(DATE,grade.Value(DATE))
allgrades.Add(cD)
b
$ b cht_main.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days
cht_main.ChartAreas(0).AxisX.LabelStyle.Angle = -90
Dim gradesDateSorter = New gradesDateSorter )
allgrades.Sort(gradesDateSorter)
对于每个成绩在allgrades
如果没有subjects.ContainsKey(Integer.Parse(grade(SUBJECTID)))然后
subjects.Add (Integer.Parse(grade(SUBJECTID)),New ArrayList)
结束如果
Dim gradeDict As New Dictionary(Of String,String)
gradeDict.Add(DATE,grade (DATE))
gradeDict.Add(GRADE,grade(GRADE))
subject(Integer.Parse(grade(SUBJECTID)))Add(gradeDict)
Next
对于每个主题在主题中
'添加系列
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
对于每个成绩在subject.Value
cht_main.Series(cht_main.Series.Count - 1).Points.AddXY(Date.Parse(grade )),Double.Parse(grade(GRADE)))
下一页
下一页

在上一行的第五行,我评论了 IsXValueIndexed = True ,因为当我激活它时,图表生成一个大红色错误交叉。






解决方案



设置X轴上的时间间隔窍门! / p>

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

Skippy 的解决方案

解决方案

是的,我同意迈克尔。


$ b

 

code> myStripLine1.IntervalOffset = 4

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



将此值设置为1将为每个x轴值提供一个值,作为整数(在这种情况下为天)

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

并声明要输入的x轴值:

  DateTimeIntervalType.Days 

声明
Public Sub Add(_
labelsStep As Double,_
intervalType As DateTimeIntervalType,_
format As String _

End Sub

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

'如迈克尔的答案所示解析为字符串。

Dim格式为String =MM.dd.yyyy
Dim actualDate as Date = Date.ParseExact(yourDate,format)
pre>

正如Michael在他的评论中提到的。
通过设置

  mySeries.XValueIndexed = True 

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



如下面的引文所解释,


系列中的每个数据点都有X和Y值,用于确定其在绘图区域中的位置。对于某些图表,点的X值不重要,不必提供。在这种情况下,绘图区域中的点位置仅由它们的点索引(即它们在Points集合中的位置)及其Y值确定。



当X值是索引的,数据点索引,而不是点的X值,用于确定沿着分类(X)轴的点的位置。例如,在下面的图1中,示出了显示相同数据的两个图表。然而,第一个图表使用非索引X值,因此这些点的X值确定它们沿x轴的位置。第二个图表是索引的,因此它的点索引用于确定它们沿x轴的位置。在这种情况下,X值只用于轴标签,而不再使用。


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



我在以下网站提供了有关间隔和间隔偏移的原始信息:



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



这里讨论数据类型并解决您的问题


在每个日期,对所有系列输入一个新点,但只有那些具有重要值的点被突出显示



例如,假设您想创建一个重新出现的StripLine以突出周末。您将间隔设置为7,其类型为天。由于第一个点是星期天,因此将IntervalOffset设置为6(表示星期的第6天),将其类型设置为Days。结果图表不显示第一个StripLine。


这是设置间隔的说明。


当使用Chart的Interval和IntervalOffset属性时,一个很好的经验法则是,IntervalOffset应该是一个比间隔更低的间隔幅度(即间隔天数/ IntervalOffset Hours,Interval Years / IntervalOffset Months等)。


我添加了这些来源:


  1. 您的参考

  2. 为了证明我已经在确定问题后进行研究, 。




Florian,您可以显示x轴的标签,属性等的代码? - yvytty昨天



你曾经考虑过第三方绘图组件,如ZedGraph?很可能这样的小警告已经覆盖那里。试一试! - Neolisk昨天





<
$ b

并且:查看您的代码后


澄清,你想每天绘制价值?我想我有你的解决方案,只是需要澄清 你有vb.net 中的所有工具



@yvytty ,日期不必是每天,也可能没有价值长时间,我不想在我的图表中没有数据的大跨度。实际上,我也可以在X轴值写一些示例文本,日期只是混乱。主要的问题是VB图表以某种方式计算在X轴上的描述非常大的利润


它不显示您已格式化日期和日期字符串。还需要考虑到,你没有使用en-US日期格式(我在澳大利亚,所以我们有和你一样的格式)。默认日期类型为en-US。



请参阅 DateTime.ParseExact 方法



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



我从MSDN取得了片段。

  Dim dateString,格式As String 
Dim结果作为日期
Dim供应商As CultureInfo = CultureInfo.InvariantCulture

解析日期和时间与自定义说明符。
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)

请参阅link:
http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx


DateTime.ToString(IFormatProvider)方法使用特定文化的短日期和长时间模式返回日期和时间值的字符串表示形式。以下示例使用DateTime.ToString(IFormatProvider)方法使用fr-FR文化的短日期和长时间模式显示日期和时间。




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

请参阅以下链接:
http://msdn.microsoft.com/ en-us / library / system.datetime.aspx



所以它应该这样:

 'note 
导入System.Globalization

Dim格式为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)
'成绩不是double类型


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 a description (e.g. "01.01.2013", "05.02.2013" and so on).

When the Chart is shown, I can only see two descriptions, even if there would be space for much more descriptions. The line gets displayed correctly, but there are only two points described.

I rotated the Text vertically so there is more space, but this didn't help. If I display less values (5 or 10), the descriptions get shown correctly.

This is how it actually looks like (the descriptions are actually Strings, not Dates).

Thank you for your help!

EDIT: My Code:

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)

On every date, a new point gets entered for all series, but only those points where they have important values get highlighted. Those values between are calculated mathematically.

One example to explain this: I got two series, one has two values (6 and 4) on point "01.01.2013" and "03.01.2013". The other series has 3 values (4,6,5.5) on "01.01.2013","02.01.2013" and "03.01.2013". When I just display them, the first series will end at the second date, even if there was a value for the third date. I solved this by filling a dummy value at the first series with date "02.01.2013" which is just the average at this point (=5). This point simply does not get highlighted with a marker bullet. This is how I draw my graph.

EDIT2:

After Skippy's answer and comment, my new trial. The variable MainForm.grades is a Dictionary(Of Integer,Dictionary(Of String, String)) which contains around 150 grades

    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

On the 5th last row I commented IsXValueIndexed=True because when I activated it, the chart gets generated with a big red error cross.


SOLUTION

Setting the Interval on the X-Axis does the trick!

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

Solution by Skippy

解决方案

Yes I agree with Michael. I can only add to the explanation at this point.

By setting your interval:

myStripLine1.IntervalOffset = 4

You are guaranteeing that your X-axis values will be plotted only, at frequency of 4 " generic x-axis" values:

Setting this to vale to 1 will give a value for every x-axis value, that is incremented as a whole number (in this case days)

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

And to declare the x-axis values to type:

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)

As mentioned by Michael in his comment. By setting the

mySeries.XValueIndexed = True

Every indexed X-axis value will be plotted.

As explained in the following quote, with the link provided.

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

I sourced my original information regarding intervals and interval offsets at the following site:

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

Here it discusses datatype and addresses your issue of highlighted values.

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.

This is a an explanation for setting the interval.

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.).

I have added these sources:

  1. For your reference
  2. To show I have, also, done my research after ascertaining the problem, as stated in my comments above.

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

In response to ZedGraph I advised:

And: After viewing your code

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

It doesn't show that you have formatted your date and date string. There also needs to be taken into account, that you are not using the en-US date format (I'm in Australia, so we have the same format as you). The default date type is for en-US.

Please refer to DateTime.ParseExact Method

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

I have taken snippets from 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)

See link: 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

Please see this link: http://msdn.microsoft.com/en-us/library/system.datetime.aspx

So it should go, something like this:

'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

ALSO:

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

这篇关于图表:在X轴上显示更多的值描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆