Przeniesienie tablicy/obiektu do funkcji

0

Dzień dobry,


var chart = function(sv,ev,dane,obiekt,interval)
{

  var chart = new CanvasJS.Chart(obiekt,
  {
    title:{text:""},
    animationEnabled:false,
        axisX:{


            interval: 1

        },
        axisY: {
            interval: interval,
            title: "",
            suffix: zl
        },
        legend: {
            verticalAlign: "bottom",
            horizontalAlign: "center"
        },



        data: [{        
            showInLegend: false,
            legendMarkerType: "square",
            type: "area",
            color: "#1ab394",
            markerSize: 7,
            dataPoints:[
              {x:1, label:"02/2020" , y:    dane.d1  },
              {x:2, label:"02/2020" , y:    dane.d2  },
              {x:3, label:"03/2020" , y:    dane.d3  },
              {x:4, label:"04/2020" , y:    dane.d4  },
            ]
        },
        {

            type: "area",
            color: "transparent",
            dataPoints: [
            {x:1 , y:      1,  toolTipContent:null}
            ]
        }


        

        ]
    });

chart.render();


return false;

}

I chciałbym wyciągnąć "dataPoints" poza obiekt CanvasJS.Chart jednak poniższy kod ze zmienną "przeniesienie" ne działa. Proszę o podpowiedź w jaki sposób poprawnie utworzyć tego typu zmienną.


var chart = function(sv,ev,dane,obiekt,interval)
{


var przeniesienie=[

              {x:1, label:"02/2020" , y:    dane.d1  },
              {x:2, label:"02/2020" , y:    dane.d2  },
              {x:3, label:"03/2020" , y:    dane.d3  },
              {x:4, label:"04/2020" , y:    dane.d4  },
];


  var chart = new CanvasJS.Chart(obiekt,
  {
    title:{text:""},
    animationEnabled:false,
        axisX:{


            interval: 1

        },
        axisY: {
            interval: interval,
            title: "",
            suffix: zl
        },
        legend: {
            verticalAlign: "bottom",
            horizontalAlign: "center"
        },



        data: [{        
            showInLegend: false,
            legendMarkerType: "square",
            type: "area",
            color: "#1ab394",
            markerSize: 7,
            dataPoints:przeniesienie
        },
        {

            type: "area",
            color: "transparent",
            dataPoints: [
            {x:1 , y:      1,  toolTipContent:null}
            ]
        }


        

        ]
    });

chart.render();


return false;

}

2
catshy napisał(a):

I chciałbym wyciągnąć "dataPoints" poza obiekt CanvasJS.Chart jednak poniższy kod ze zmienną "przeniesienie" nie działa.

Sprawdzałeś, czy wyświetla się błąd w konsoli? Bo przydałby się jakiś komunikat, co dokładnie nie działa.

1 użytkowników online, w tym zalogowanych: 0, gości: 1