简体   繁体   English

用工作日标记 System.Windows.Forms.DataVisualization.Charting 图表中的 X 轴

[英]label the X axis in a System.Windows.Forms.DataVisualization.Charting chart with weekdays

The x dimension of my graph is composed of double values which contain the number of minutes.我的图表的 x 维度由包含分钟数的双精度值组成。 They cover a range of 1 week.它们涵盖了 1 周的范围。 While I have no problem with correctly displaying those values on the graph, I would like the X-axis labels to be week-days (the hour:minute precision is not important on the labels, but is present on the graph, because monday at 15:00 is a point between monday and tuesday, but placed before the points monday at 16:00, for example).虽然我在图表上正确显示这些值没有问题,但我希望 X 轴标签是工作日(小时:分钟精度在标签上并不重要,但出现在图表上,因为星期一在15:00 是星期一和星期二之间的一个点,但例如放置在星期一 16:00 点之前)。 Any idea how I can achieve this?知道我如何实现这一目标吗?

PS: the mentioned values in minutes are obtained from: #(day of week)*24*60 + hours*60 + minutes, where #(day of week) = 0 for monday, 1 for tuesday, ... PS:提到的分钟值来自:#(星期几)*24*60 + 小时*60 + 分钟,其中#(星期几) = 0 表示星期一,1 表示星期二,...

I have been analyzing the Microsoft code samples here: Samples Environments for Microsoft Chart Controls .我一直在这里分析 Microsoft 代码示例: Microsoft Chart Controls 的示例环境 The behavior you wish may be accomplished by either option below:您希望的行为可以通过以下任一选项来完成:

  1. Using multiple Y axes ( screenshot ) with realignment of your data.使用多个 Y 轴(屏幕截图)重新对齐您的数据。 Implies having a copy of you original data points.意味着拥有原始数据点的副本。 Then just modify axis properties for your second series.然后只需修改第二个系列的轴属性。 Full code available in the samples.示例中提供了完整代码。 Obviously you have to do that for the X axis.显然,您必须对 X 轴执行此操作。
  2. Using primary and secondary axes: AxisX and AxisX2.使用主轴和副轴:AxisX 和 AxisX2。
  3. Using custom labels ( screenshot ).使用自定义标签(截图)。 Code sample available at the link above.上面链接中提供的代码示例。

You can set the corresponding Axis IntervalType of the ChartArea to Days - assuming it is ok for you to have to transform minutes to days.您可以将 ChartArea 的相应 Axis IntervalType 设置为 Days - 假设您可以将分钟转换为天。 You state the core idea here is to have a "time" based graph, no matter whether its minutes or days simply divide minutes by /(60[minutes]*24[hours])你在这里陈述的核心思想是有一个基于“时间”的图表,无论是分钟还是天,只需将分钟除以 /(60[minutes]*24[hours])

Your desire for bigger time spans can be accomplished by calculating minutes related to a fixed start time/date.您可以通过计算与固定开始时间/日期相关的分钟数来实现您对更大时间跨度的渴望。

var chartArea = new System.Windows.Forms.DataVisualization.Charting.ChartArea
            {
                Name = "ChartArea1",
                AxisX = new System.Windows.Forms.DataVisualization.Charting.Axis
                {
                    IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Days
                }
            };

            //...//
            chart.ChartAreas.Add(chartArea);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有System.Windows.Forms.DataVisualization.Charting的互斥和从属轴 - Reciprocal & dependent axis with System.Windows.Forms.DataVisualization.Charting 如何在X轴上为System.Windows.Forms.DataVisualization.Charting设置DateTime范围? - How do you set DateTime range on X axis for System.Windows.Forms.DataVisualization.Charting? 将System.Windows.Forms.DataVisualization.Chart图表控制插入到Word文档中 - Inserting System.Windows.Forms.DataVisualization.Charting chart contorl into Word document 是否有Excel图表对象到System.Windows.Forms.DataVisualization.Charting转换器? - Is there an Excel Chart Object to System.Windows.Forms.DataVisualization.Charting converter around? 如何在System.Windows.Forms.DataVisualization.Charting中设置与主要Axis(AxisX)不同的次要Axis(AxisX2)的最小值和最大值 - How to Set Secondary Axis(AxisX2) Minimum and Maximum different from Primary Axis(AxisX) in System.Windows.Forms.DataVisualization.Charting Xaml,System.Windows.Controls.DataVisualization.Charting-将X轴标签显示为秒而不是时间? - Xaml, System.Windows.Controls.DataVisualization.Charting - Display X-Axis label as seconds instead of Time? 设置chart.ChartAreas [0] .Axes [0] .Maximum为“ Auto”时,是否存在System.Windows.Forms.DataVisualization.Charting.Chart的错误? - Is there a bug of System.Windows.Forms.DataVisualization.Charting.Chart, when setting chart.ChartAreas[0].Axes[0].Maximum as “Auto”? C#:System.Windows.Forms.DataVisualization.Charting.Chart设置行大小 - C#: System.Windows.Forms.DataVisualization.Charting.Chart Set Line Size 是否可以以十六进制显示DataVisualization.Charting.Chart的x轴值? - Is it possible to display the x-axis values of the DataVisualization.Charting.Chart in hexadecimal? System.Web.UI.DataVisualization.Charting中的雷达图选择性标签旋转? - Radar chart selective label rotation in System.Web.UI.DataVisualization.Charting?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM