Stephan: Wie mehrstufigem Array eine Variable zuweisen?

Beitrag lesen

Hallo Leute,

ich habe ein Array mit Standardwerten der folgenden Form:


var data = {
	labels : ["3","2","1","12","11","10","9","8","7","6","5","4"],
	datasets : [
		{
			label: "Werte1",
			fillColor: "rgba(220,220,220,0.5)",
			strokeColor: "rgba(220,220,220,0.8)",
			highlightFill: "rgba(220,220,220,0.75)",
			highlightStroke: "rgba(220,220,220,1)",
			data : [1,2,3,4,5,6,5,4,3,2,1,5]
		},
		{
			label: "Werte2",
			fillColor: "rgba(151,187,205,0.5)",
			strokeColor: "rgba(151,187,205,0.8)",
			highlightFill: "rgba(151,187,205,0.75)",
			highlightStroke: "rgba(151,187,205,1)",
			data : [6,3,6,3,2,4,2,4,5,1,5,1]
		}
		]
}

Nun hab ich die eigene Werte für Label und Data in einer Variable stehen, weiß aber nicht, wie ich die Werte jetzt korrekt in das Array einbaue. Die Werte vom Label müssen in Anführungszeichen stehen. Die Werte von werte1 und werte2 ohne Anführungszeichen.


var labels = '"Mar","Feb","Jan"';
var werte1 = '1,2,3';
var werte2 = '6,5,4';
var data = {
	labels : [labels],
	datasets : [
		{
			label: "Werte1",
			fillColor: "rgba(220,220,220,0.5)",
			strokeColor: "rgba(220,220,220,0.8)",
			highlightFill: "rgba(220,220,220,0.75)",
			highlightStroke: "rgba(220,220,220,1)",
			data : [werte1]
		},
		{
			label: "Werte2",
			fillColor: "rgba(151,187,205,0.5)",
			strokeColor: "rgba(151,187,205,0.8)",
			highlightFill: "rgba(151,187,205,0.75)",
			highlightStroke: "rgba(151,187,205,1)",
			data : [werte2]
		}
	]
}