Scenario
I'll try to simplify my question with description and code.
I would like to refresh line chart with javascript after drop down list item was selected,
which the selected event has been triggered.
The line chart was in a partial view,
which its initial shown data was passed in with ViewBag as local data and binded with line chart .
What I've tried so far
I was able to trigger javascript with custom select event,
and retrieve the drop down list selected item,
then I'll passed the select item as a query condition back to controller,
after getting new list of data from database,
I need to pass these data back to partial view where the line chart is to refresh it.
Question1
My line chart data was first binded with ViewBag local data binding.
Should I just return to partial view and pass new data in with ViewBag,
and let it automatically refresh the chart since return back to the partial view forcelly renders it again?
Question2 (Extension of question1)
I would have 4 line charts in the partial view,
each chart has a dropdown list to refresh the chart,
If a dropdown list item was selected,
would the other chart shows nothing? Since I've binded data with ViewBag in the beggining,
If so, how can I prevent the other 3 chart to refresh(loosing data)?
Code
Partial View with line chart and drop down list (the three other linechart was not listed )
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
//line chart datas
var instDatas = (MyDataViewModel)ViewBag.instsData;
}
<div>
@(Html.Kendo().TabStrip()
.Name("chart-tabstrip")
.Animation(animation => animation.Open(effect => effect.Fade(FadeDirection.In)))
.Items(tabstrip =>
{
tabstrip.Add().Text("My Monitoring tab 1")
.Selected(true)
.Content(@<text>
<div>
@(Html.Kendo().DropDownList()
.Name("DTData-DropDown")
.DataTextField("InstNo")
.DataValueField("InstID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("MyAction", "MyController", new {MyQueryParams});
});
})
.Value("default")
.HtmlAttributes(new { style = "width: 250px" })
)
@(Html.Kendo().Chart(instDatas.DTDataViewModel)
.Name("dtchart")
.Title("dtchart")
.Legend(legend => legend
.Position(ChartLegendPosition.Bottom)
)
.ChartArea(chartArea => chartArea
.Background("transparent")
)
.SeriesDefaults(seriesDefaults =>
seriesDefaults.Line().Style(ChartSeriesStyle.Smooth)
)
.Series(series => {
series.Line(model => model.ReadData).Name("ReadData");
})
.ValueAxis(axis => axis
.Numeric()
)
.CategoryAxis(axis => axis
.Categories( m => m.ReadTime)
.Type(ChartCategoryAxisType.Date)
.BaseUnit(ChartAxisBaseUnit.Fit)
.Labels(labels => labels.Rotation(-90))
.Crosshair(c => c.Visible(true))
.AutoBaseUnitSteps(config => config.Milliseconds(1))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Shared(true)
.Format("{0:N0}")
)
)
</div>
</text>);
})
.HtmlAttributes(new{style = "width : 1400px; margin: 30px auto"})
)
</div>
<script>
//Dropdown list select event function(Haven't add it)
function instDataChartDropDownSelect(e) {
var dataItem = this.dataItem(e.item);
var instNo = dataItem.value;
}
</script>