<div>
Select DataSource:<select id="SelectDataSet" onchange="selectSource(this)" style="width:100px;height:20px">
<option value="SelectDataSet">5 points DataSet</option>
<option value="DataSet1">10 points DataSet</option>
</select>
</div>
[MVC]
@{
<div>
@(Html.EJ().Chart("chart").Series(sr =>
{
sr.DataSource(ViewBag.datasource).XName("XValue").YName("YValue").Add();
})
.Load("onchartload")
.PrimaryXAxis(xAxis => xAxis
.Font(font => font.Size("8px"))
.LabelIntersectAction(LabelIntersectAction.Trim))
.PrimaryYAxis(yAxis => yAxis.ValueType(AxisValueType.Double))
.EnableCanvasRendering(true)
.SeriesRendering("RenderSeries") //SeriesRendering event handler for chart.
.CanResize(true)
.Zooming(zn => zn.Enable(false).EnableMouseWheel(false))
)
</div>
}
Please find the below screen shot
In the partial view we have used ajax postback to add the datasource to the chart while clicking the dropdown in the main view.
Please find the below code snippet
[JS]
<script>
function selectSource(sender) {
var param = sender.selectedIndex == 0 ? 5 : 10;
$.ajax({
type: "POST",
url: "TreeGrid/Getjsondata",
data: { 'data': param },
async: false,
success: function (data) {
var chartObj = $("#chart").ejChart("instance");
chartObj.model.series[0].dataSource = data;
chartObj.redraw();
}
});
}
function RenderSeries() {
var chartObj = $("#chart").ejChart("instance");
chartObj.model.series[0].type = "column";
chartObj.model.series[0].name = "SeriesName Changed";
}
</script>
Screen shot
Please find the sample from the below location.
Sample link: https://www.syncfusion.com/downloads/support/forum/119918/ze/partial-423758284
Please let us know if you have any concerns.
Regards,
Sanjith K.?
Please add notes on the JS code.
thanks
function renderChart() { var val1 = parseInt(document.getElementById("input").value); for (var i = 0; i < val1; i++) { $.ajax({ type: "POST", url: '@Url.Action("Getdata","Home")', data: { 'data': i }, async: false, success: function (data) { $("#home").html(data); }, }); }
} |
public ActionResult Getdata(int data) { return PartialView("PartialView",data); } |