Jquery append funktionselement
    
ralphi
    
    
      
    
  - javascript
 
Hi Leute,
ich suche nach dem Syntax, bei dem ich Elemente zu einer Jquery Funktion zufügen kann. Es geht um FLOT Diagramme mit dem recht einfachen Code (zB. 2 Kurven):
  
// daten1 und daten2 sind arrays  
  
$.plot("#placeholder", [  
		  
		{  
			label: "linie1",  
			data: daten1,  
			lines: { show: true }  
		},  
		{  
			label: "linie2",  
			data: daten2,  
			points: { show: true }  
		}	  
  
]);
Jetzt möchte ich gerne später eine dritte Kurve (per Ajax) hinzufügen:
		$.plot("#placeholder").append ([  
			{  
				label: "linie3",  
				data: daten3,  
				points: { show: true }  
			}
So funktionierts aber nicht :-(
Kann mir jemand helfen?
]);
Viele Grüße aus LA
Meine Herren!
Jetzt möchte ich gerne später eine dritte Kurve (per Ajax) hinzufügen:
	$.plot("#placeholder").append ([  
{ label: "linie3", data: daten3, points: { show: true } }
>   
> So funktionierts aber nicht :-(  
  
Rateversuche führen nur selten zum Ziel ;)  
  
Probiere doch mal folgendes aus:  
  
Statt das Daten-Array plain an die Funktion zu übergeben, speichere es erst in einer Variablen, so können wir später wieder auf das Daten-Array zugreifen, also:  
  
~~~javascript
var plotData = [  
  
                {  
                        label: "linie1",  
                        data: daten1,  
                        lines: { show: true }  
                },  
                {  
                        label: "linie2",  
                        data: daten2,  
                        points: { show: true }  
                }  
  
];  
  
$.plot('#placeholder', plotData );
In deiner Ajax-Callback-Funktion fügst du dann den neuen Eintrag einfach zum Array hinzu:
plotData.push( ajaxData );
Eventuell musst du dann manuell dafür sorgen, dass das Bild neu gezeichnet wird:
$.plot('#placeholder').draw();
Die erste Anlaufstelle für solche Probleme sollte die API-Dokumentation sein.
mensch!
ja klar ist ja gar keine Funktion, sondern ein Array.
Das Jquerykonstrukt werd ich nie verstehen :-|
so funktionierts natürlich - danke:
	        var plotArray = [  
		  
		{  
			label: "linie1",  
			data: daten,  
			lines: { show: true }  
		}  
		];  
		  
		  
		plotArray.push (  
			{  
				label: "linie3",  
				data: d6,  
				points: { show: true }  
			}  
		);  
	  
		$.plot("#placeholder", plotArray);  
Viele Grüße aus LA
mensch!
ja klar ist ja gar keine Funktion, sondern ein Array.
Das Jquerykonstrukt werd ich nie verstehen :-|so funktionierts natürlich - danke:
        var plotArray = [  
{ label: "linie1", data: daten, lines: { show: true } } ]; plotArray.push ( { label: "linie3", data: d6, points: { show: true } } ); $.plot("#placeholder", plotArray);
>   
>   
>   
> Viele Grüße aus LA  
Viele Grüße aus LA
-- 
ralphi