未捕获的图的尺寸无效,宽度= null,高度= null,用于flot charts api

时间:2014-02-12 05:35:38

标签: jquery jquery-ui-tabs flot

我正在使用flot chart API来显示图表,并且我成功地绘制了数据。 我在一个页面中加载大约30个图表,我在ui-tab中渲染它们。所有图形都完美呈现,页面工作正常。但我仍然收到此错误。 我对所有图形使用了不同的div id,高度和宽度都给了所有的div。我从昨天起就无法找到解决方案。我在中央页面中包含了flot所需的所有js。 请帮助我。

3 个答案:

答案 0 :(得分:6)

非活动标签中的div元素是不可见的,在显示之前没有宽度或高度。这可能会导致flot出现问题,此处的默认做法是仅在显示选项卡时呈现图形。

另一种方法是将div绝对定位在页面之外,渲染绘图图形,然后将div移动到标签中。

答案 1 :(得分:1)

我有同样的问题。一个不同的解决方案对我有用。

  • 确保您设置高度和宽度style =“width:100%; height:400px”(查看Invalid dimensions for plot, width = 0, height = 400 inside of hidden tab
  • 确保flot没有找到一些不存在的div。这是因为我从一个有三个图的页面复制它,而我使用了第一个和第三个。我可以通过使用chrome的控制台找到它(它在找不到页面中的第二个div之后崩溃。因此第三个没有被绘制。只是注释掉js中未使用的绘图并且它工作正常)

答案 2 :(得分:0)

您可以在单击选项卡后移动事件以生成绘图 - 请参阅:JQuery onchange in tabs event

例如:

Private Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
Dim count As Integer
i = 3
j = 0
count = 3
dtr = 0.0174533 'degrees to radians calculation
RTD = 57.2958 'radians to degrees
LatFactor = 69.172 'miles in 1 degree change in lat



'Finds how many locations there are around whs as j
Do While Cells(i, 2) <> ""
    j = j + 1
    lats = lats + Cells(i, 2)
    Longs = Longs + Cells(i, 3)
    i = i + 1
Loop


'Create arrays of lats and longs starting at  0
Dim lat() As Variant
ReDim lat(0 To j)
Dim lon() As Variant
ReDim lon(0 To j)
For x = 1 To j
    lat(count - 3) = Cells(count, 2)
    lon(count - 3) = Cells(count, 3)
    count = count + 1
Next

R = 3959 'Radius of earth
whsLat = Cells(2, 2) 'Lattitude of Whs in NOT Radians
whsLon = Cells(2, 3) 'Lattitude of whs NOT in rads
whsLatr = Cells(2, 2) * dtr
whsLonr = Cells(2, 3) * dtr


'Calculates distance from warehouse to location 1 as d
'uses haversine formula-as crow flies

Dim Distances() As Variant
ReDim Distances(0 To j)
For x = 1 To j
    Clat = lat(x - 1) * dtr
    deltaLat = (lat(x - 1) - whsLat) * dtr
    deltaLon = (lon(x - 1) - whsLon) * dtr
    a = (Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2)) +                
(Math.Cos(whsLatr) * Math.Cos(Clat) * Math.Sin(deltaLon / 2) *         
Math.Sin(deltaLon / 2))
    c = 2 * Math.Atn((Math.Sqr(a) / Math.Sqr(1 - a)))
    d = R * c
    Distances(x - 1) = d 'distance values
    Cells(x + 2, 13) = d
Next
TotalMiles = WorksheetFunction.Sum(Distances)
step = 1


'Calculate optimum location using halves

Olat = lat(0)
Olon = lon(0)
OLatr = lat(0) * dtr
OLonr = lon(0) * dtr
Dlat = lat(1)
DLatr = lat(1) * dtr
Dlon = lon(1)
Dlonr = lon(1) * dtr
LatChange = (lat(1) - Olat) * dtr
LonChange = (lon(1) - Olon) * dtr

'Counting Variables for weight
y = 3
Z = 4
ShipSum = Cells(y, 4) + Cells(Z, 4)
For x = 1 To j - 1
anew = (Math.Sin(LatChange / 2) * Math.Sin(LatChange / 2)) +     
(Math.Cos(OLatr) * Math.Cos(DLatr) * Math.Sin(LonChange / 2) * 
Math.Sin(LonChange / 2))
cnew = 2 * Math.Atn((Math.Sqr(anew) / Math.Sqr(1 - anew)))
dnew = R * cnew
'Calculate new lat and long
hyp = dnew / 2 ' Total distance moved
adj = Abs(LatFactor * (Dlat - Olat)) 'y distance
Degree = WorksheetFunction.Acos(adj / dnew * dtr) 'degree from 90
If (Dlat - Olat) > 0 Then NewLat = Olat + (Cells(Z, 4) / (ShipSum)) *         
Abs(hyp / LatFactor * Math.Cos(Degree) * RTD) 'New lattitude if going up
If (Dlat - Olat) < 0 Then NewLat = Olat - (Cells(Z, 4) / (ShipSum)) *     
Abs(hyp / LatFactor * Math.Cos(Degree) * RTD) 'New Lattitude if going down
Opp = (Dlon - Olon) * Math.Cos(NewLat * dtr) 'x distance adjusted for polar     
flattening
If (Dlon - Olon > 0) Then NewLon = Olon + (Cells(Z, 4) / (ShipSum)) *     
Abs(Opp) 'new long
If (Dlon - Olon < 0) Then NewLon = Olon - (Cells(Z, 4) / (ShipSum)) *     
Abs(Opp)
Olat = NewLat 'Setting new origin
Olon = NewLon
OLatr = NewLat * dtr
OLonr = NewLon * dtr
If x < j Then
    Dlat = lat(x + 1) 'If there is another iteration, set new destination
    DLatr = lat(x + 1) * dtr
    Dlon = lon(x + 1)
    Dlonr = lon(x + 1) * dtr
    LatChange = (lat(x + 1) - Olat) * dtr
    LonChange = (lon(x + 1) - Olon) * dtr
    y = y + 1
    Z = Z + 1
    ShipSum = ShipSum + Cells(Z, 4)
End If
Next

Cells(3, 8) = NewLat
Cells(3, 9) = "-" & NewLon

whsLat = NewLat 'Lattitude of New Whs in NOT Radians
whsLon = NewLon 'Lattitude of whs NOT in rads
whsLatr = NewLat * dtr
whsLonr = NewLon * dtr


'Calculates distance from warehouse to location 1 as d
'uses haversine formula-as crow flies

Dim NewDistances() As Variant
ReDim NewDistances(0 To j)
For x = 1 To j
    Clat = lat(x - 1) * dtr
    deltaLat = (lat(x - 1) - whsLat) * dtr
    deltaLon = (lon(x - 1) - whsLon) * dtr
    a = (Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2)) +     
(Math.Cos(whsLatr) * Math.Cos(Clat) * Math.Sin(deltaLon / 2) *     
Math.Sin(deltaLon / 2))
    c = 2 * Math.Atn((Math.Sqr(a) / Math.Sqr(1 - a)))
    d = R * c
    Cells(x + 2, 10) = d
    NewDistances(x - 1) = d 'distance values
Next
NewTotalMiles = WorksheetFunction.Sum(NewDistances)
Cells(j + 3, 10) = NewTotalMiles
Worksheets("Sheet1").Range("K3:K100").ClearContents

i = 3
Do While i < 44
    Cells(i, 11) = Cells(i, 10) * Cells(i, 4)
    i = i + 1
Loop
Cells(11, 11) = Cells(3, 11) + Cells(4, 11) + Cells(5, 11) + Cells(6, 11) +     
Cells(7, 11) + Cells(8, 11) + Cells(9, 11) + Cells(10, 11)
End Sub