PDA

View Full Version : dynamic Scaling for charts



hepzibahr
10-24-2011, 10:46 AM
Private Sub Worksheet_Activate()
Dim maxvalue ,minvalue ,maxvalueJahr,minvalueJahr As Long
minvalue = Sheets("tabelle1").Range("H15").Value
maxvalue = Sheets("tabelle1").Range("H16").Value
minvalueJahr = Sheets("tabelle1").Range("H24").Value
maxvalueJahr = Sheets("tabelle1").Range("H25").Value
'Debug.Print minvalue
'Debug.Print maxvalue
Sheets("Projekt").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.HasAxis(xlValue) = True
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScale = minvalue
ActiveChart.Axes(xlValue).MaximumScale = maxvalue
'ActiveChart.Axes(xlValue).MajorUnit = 300000
'ActiveChart.Axes(xlValue).MinorUnit = 40000
ActiveChart.Refresh
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.HasAxis(xlValue) = True
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScale = minvalueJahr
ActiveChart.Axes(xlValue).MaximumScale = maxvalueJahr
ActiveChart.Refresh
End Sub


When the min and max value are greater than zero then the graph is working fine . when the value is zero the minvalue of the chart changes to auto or fixed with value as -1.0.


I changed the scaling of the chart to fixed with 0.0 and saved the chart .But still after activating the chart it reverts back to auto or fixed with -1.0.

Hope there is a way out for this .