Dynamic Milestone Trend Analysis Graph needs same y-axis as x-axis in Excel with VBA

时间:2015-07-28 16:35:55

标签: excel excel-vba graph excel-2013 vba

After a couple hours of work I come to you guys with this graphing problem. I need to create a Milestone-Trend-Analysis which can be seen on the german wikipedia , though not in the english version.

General Information

In short, the diagram has report dates on the x-axis (for now, on every first of the month, another report is due). The y-axis should mirror the x-axis completely. In length and also the tickmarks. The dates get bigger from the bottom to the top. In my case the x-Axis is on top of the diagram.

Every report consists of a number of "due-dates", one for each assignement in progress. They are the estimated "finishing dates" of that particular assignement.

If the estimated finishing date stays the same in the next report period, the graph for that assignement stays on the same level. If the estimate is earlier, the graph trends down. Normally they go up, since the assignement has some delay :-D

The x-axis needs to be dynamic, since the whole project is basically finished when its last assignement is finished. If one of the assignements is running late, the whole project gets delayed an thus the x-axis needs to be longer/get more ticks. Since the y-Axis mirrors that, it has to change too.

MY PROBLEM

The x-axis has a number of discreet values, since the reports come in every month, or every two weeks. But that does not change. The values for the finishing dates are continuous, since the assignements can be terminated whenever.

That leaves me with the problem of having to cut the y-axis in equal-size chunks, although the months of the year are not equal in size. At least that is, what I think excel forces me to do.

I can assign a max limit and a min limit for the y-axis and I can assign a distance between each main tickmark. Since Excel works with a continous number for each date, the 2014/01/01 would be 41640. And 2015/01/01 is 42005. Since I have 12 month on the x-axis and I need 12 on the y axis, I would have to have the main Ticks at a distance of 30.42 ... which gives me the following Months on my axis

January January March .... December December

Does anyone know an answer for this? Is there a way to have excel make the tickmarks on the y-axis not equal distance?

Any input greatly appreciated.

Kaz

2 个答案:

答案 0 :(得分:0)

我没有找到使Excel具有可变刻度标记距离的方法。但是既然我没有这样做,那我就不得不把这个月变得很长。

现在这对我有用:

'calculate the norm for different type of month including Schaltjahr
Select Case cellMonth

        'February
    Case 2

        'Schaltjahr and Schaltjahrhundert
        If (cellYear Mod 4 = 0) Or (cellYear Mod 400 = 0) Then

            resultDay = (30 / 29) * cellDay

        Else

            resultDay = (30 / 28) * cellDay
        End If

        '31 day months
    Case 1, 3, 5, 7, 8, 10, 12

        resultDay = (30 / 31) * cellDay

        '30 day months
    Case Else

        resultDay = cellDay

End Select

现在我只需要将轴缩放到numberOfMonths * 30。现在它会调整y轴的名称,这似乎是一个完全不同的故事。

卡兹

答案 1 :(得分:0)

您可以通过添加虚拟XY系列沿Y轴放置任意标签。

以下是我认为可以捕获您的问题的一些数据,以及显示数据的折线图,以及我将用于构建虚拟Y轴的数据。

我使用折线图,所以X轴至少会很容易。您只需确保将轴格式化为基本单位为天的日期轴。

Data and starting chart

以下是我构建轴的方法。

左上图:我复制了虚拟轴数据,两列数据包括标题行。我选择了图表,并使用“选择性粘贴”将数据添加为新系列,列中的数据,第一行中的系列名称,第一列中的类别(但不替换现有类别)。

右下方的图表:我右键点击添加的系列,点击更改系列图表类型,然后选择带有线条和标记的XY散点图。 Excel还将此系列放在辅助轴上。

左下图:我将添加的系列格式化为在主轴上绘制。

中右下图:我改变了垂直轴的比例,给出了第一个日期的最小值和最后一个日期的最小值(1/1/16到9/1/16) )。

下方左下图:我将垂直轴格式化为不显示标签。

下方右下图:格式格式。我格式化了虚轴系列,因此它使用了轻型gary线(与水平轴匹配)和浅灰色交叉标记(模拟刻度线)。我更改了水平轴的刻度线,使它们穿过轴,与虚拟系列的交叉标记相匹配。我在虚拟系列点的左侧添加了数据标签,模拟了垂直轴标签。

enter image description here