' Project: Weight Tracker ODS ' Module Name: Charts ' Created: 06-JAN-2010 ' Last Modfied: 10-JAN-2012 ' Description: All chart manipulations ' Update the chart base on the start/end date Sub updateChartWith(ByVal oStartDate, ByVal oEndDate) sChart = oSheets.getByName("Chart") oChart = sChart.Charts(0).EmbeddedObject ' Update chart title oChart.Title.String = "Progress from " + oStartDate.Year + "/" + oStartDate.Month+"/"+oStartDate.Day + " to " + oEndDate.Year + "/"+oEndDate.Month +"/"+oEndDate.Year ' Update chart x-axis range oChart.Diagram.XAxis.Min = DateSerial(oStartDate.Year, oStartDate.Month, oStartDate.Day) oChart.Diagram.XAxis.Max = DateSerial(oEndDate.Year, oEndDate.Month, oEndDate.Day) ' Default Y-Axis Ranges iLowWeight = 0 iHighWeight = 190 iMargin = 10 iMetric = getOption("metric") If (iMetric = 1) Then iHighWeight = 80 iMargin = 5 EndIf ' Get personal high/low weights iLow = getOption("lowweight") iLowM = getOption("lowweightm") iHigh = getOption("highweight") iHighM = getOption("highweightm") ' Calculate y-axis min (not zeroed out yet!) If ((iLow > 0) and (iLowM > 0)) Then iLowWeight = MIN(iLow, iLowM) ElseIf (iLow > 0) Then iLowWeight = iLow ElseIf (iLowM > 0) Then iLowWeight = iLowM EndIf ' Calculate y-axis max (not zeroed out!) If ((iHigh > 0) and (iHighM > 0)) Then iHighWeight = MAX(iHigh, iHighM) ElseIf (iHigh > 0) Then iHighWeight = iHigh ElseIf (iHighM > 0) Then iHighWeight = iHighM EndIf ' Update chart y-axis range (zeroed out) oChart.Diagram.YAxis.Min = MAX(iLowWeight - iMargin, 0) ochart.Diagram.YAxis.Max = MAX(iHighWeight, oChart.Diagram.YAxis.Min) + iMargin End Sub ' Run when a date is changed on the sheet Sub updateChartDates initGlobals updateChart End Sub ' Run after a recalc usually Sub updateChart oyear = getOption("startyear") updateChartLimits(oyear) End Sub ' Update the date ranges (for example, when a new year is loaded) Sub updateChartLimits(ByVal year) ' Init objects sChart = oSheets.getByName("Chart") oStartDate = getControlByName(sChart, "StartDate") oEndDate = getControlByName(sChart, "EndDate") oStartDate.DateMin.Year = year oStartDate.DateMin.Month = 1 oStartDate.DateMin.Day = 1 oEndDate.DateMin = oStartDate.DateMin oStartDate.DateMax.Year = year oStartDate.DateMax.Month = 12 oStartDate.DateMax.Day = 31 oEndDate.DateMax = oStartDate.DateMax ' oStartDate.DefaultDate = oStartDate.DateMin ' oEndDate.DefaultDate = oEndDate.DateMax ' Set to defaults if out of range (when new year is loaded) If ((oStartDate.Date.Year < year) or (oStartDate.Date.Year > year)) Then oStartDate.Date = oStartDate.DateMin End If If ((oEndDate.Date.Year < year) or (oEndDate.Date.Year > year)) Then oEndDate.Date = oEndDate.DateMax End If If ((oStartDate.Date.Month > oEndDate.Date.Month) or (oStartDate.Date.Month = oEndDate.Date.Month and oStartDate.Date.Day >= oEndDate.Date.Day)) Then oStartDate.Date = oEndDate.Date oStartDate.Date.Day = oStartDate.Date.Day - 1 End If updateChartWith(oStartDate.Date, oEndDate.Date) End Sub