无法在我的索引页 yii2 中设置局部视图

Unable to set partial view in my index page yii2

我正在尝试在 index page 处呈现部分视图,以在通过执行以下操作满足特定条件时显示图表。

Index.php

<?PHP
.
.
.
.
else if($type == "403")
{

    $columns = [
        ['class' => 'yii\grid\SerialColumn'],

        'Device_ID',
        'Customer_ID',
        'MSN',
        'kWh',
        'Data_Date_Time',


    ];
    $this->render('_kwhChart', [
        'dataProvider' => $dataProvider,
    ]) ;
}
.
.
.
.
?>
 <?=
GridView::widget([
    'dataProvider' => $dataProvider,
    //'filterModel' => $searchModel,
    'columns' => $columns
]);
?>

当某个条件成立时,我能够看到更新后的 gridview 值,但看不到局部视图,即图表。

全景图

<?PHP
  $dataPointskWh = array();
  $model = $dataProvider->getModels();

  foreach ($model as $row)
  {
    // pushing for kwh values
    array_push($dataPointskWh, 
    array("label"=>$row['Data_Date_Time'],"y"=>$row['kWh']));
  }

  ?>
            <div id="chartContainer1" style="width: 100%; height: 300px;display: inline-block;"></div>

 <script>
   var chart1 = new CanvasJS.Chart("chartContainer1", {
     exportEnabled: true,
    animationEnabled: true,
     zoomEnabled: true,
     theme: "light1",
    title:{
        text: "Voltages"
    },
    legend:{
        cursor: "pointer",
        verticalAlign: "bottom",
        horizontalAlign: "center",
        itemclick: toggleDataSeries
    },
    data: [
        {
        type: "column",
            lineColor:"red",
            legendMarkerColor: "red",
        name: "kWh",
        indexLabel: "{y}",
        //yValueFormatString: "V1#0.##",
        showInLegend: true,
        dataPoints: <?php echo json_encode($dataPointskWh, JSON_NUMERIC_CHECK); ?>
    }
    ]

});
 chart1.render();


function toggleDataSeries(e){
    e.dataSeries.visible = !(typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible);
    chart1.render();

}

注意:我使用的是提交按钮,每次点击提交按钮都会刷新页面。

我怎样才能做到这一点?

非常感谢任何帮助。

您不渲染 render() .. 您需要 .. echo

echo  $this->render('_kwhChart', [
    'dataProvider' => $dataProvider,
]) ;

<?= $this->render('_kwhChart', ['dataProvider' => $dataProvider, ]) ?>;