|
[JS]
function onChartLoad(sender) {
generateData(dataLength);
setInterval(function () { generateData(); }, 100);
}
function generateData() {
dataLength = (dataLength == undefined) ? 10 : (dataLength + 1);
$.ajax({
url: '@Url.Action("getData", "Home")',
type: "Post",
data: { 'length': dataLength },
dataType: "json",
success: function (data) {
for (var i = 0; i < data.length; i++)
data[i].date = new Date(data[i].date);
if (data.length > 50) {
var chartData = data;
data = [];
for (var j = Math.round((chartData.length / 2)) ; j < (Math.round((chartData.length / 2)) + 20); j++)
data.push(chartData[j]);
}
var chart = $("#container").ejChart("instance");
for (var i = 0; i < chart.model.series.length; i++) {
chart.model.series[i].dataSource = data;
chart.model.series[i].xName = "date";
chart.model.series[i].yName = "yValue" + (i+1);
}
chart.redraw();
},
});
} |
Hi Saravana,
GREAT!!!!
Although I had some troubles getting the attached sample running (version mismatches with nuget and so on) I did:
a.) created new aspnetcore 2.0 project
b.) added your nuget package and via bower the scripts
c.) included scripts and so on...
Then I copied the controller and the view - DONE.
Does exactly what I wanted it to do.
Now (sorry but I'm new with your controls) - I have a the same chart - but in this case I want to provide the data directly via the controller.
public IActionResult Index() { return View(BuildData()); } private DataHolder BuildData() { DataHolder dhRet = new DataHolder() { Title = "My Title"}; dhRet.DataPoints = new List<ChartData>(); Random r = new Random(); DateTime date = new DateTime(2015, 01, 01); for(int i = 0; i < 30; i++) { dhRet.DataPoints.Add(new ChartData(date.AddDays(i + 1), r.Next(10, 50), r.Next(0, 3000), r.Next(0, 100))); } dhRet.MaxY3 = dhRet.DataPoints.Select(a => a.YValue3).Max(); dhRet.MinY3 = dhRet.DataPoints.Select(a => a.YValue3).Min(); return (dhRet); } public class DataHolder { public string Title { get; set; } public double MinY3 { get; set; } public double MaxY3 { get; set; } public List<ChartData> DataPoints { get; set; } } public class ChartData {
//the class you provided....
So I get a fixed number of points (not important), the range (min, max) of the yAxis3 is in the model and the datapoints too.
I guess I can do something like:
<e-range max="@Model.MaxY3" min="@Model.MinY3">e-range>
with the axis. And there is (I also guess) a way to
a.) bind the data from the model like somehowsource="@Model.DataPoints"
b.) assign the property to the axis somehow
EDIT - SOLUTION FOUND
I messed around a bit with the control and found the solution...
a.) remove the loaded handler
b.) change (near the bottom) to
<e-common-series-options type="@SeriesType.Line" datasource="@Model.DataPoints"> e-common-series-options> <e-chart-series> <e-series name="India" fill="#f44242" x-name="Date" y-name="YValue1"> e-series> <e-series name="Japan" fill="#079e46" y-axis-name="yAxis2" x-name="Date" y-name="YValue2"> e-series> <e-series name="China" fill="#07229e" y-axis-name="yAxis3" x-name="Date" y-name="YValue3"> e-series> e-chart-series>
The only thing which pestered me was the fact, that the data is not serialized as JSON I hade to change the case from yValu.. to YVal...
By the way - your support is really outstanding! Thank you very much for your help!
Manfred
|
[C#]
public class ChartData
{
public ChartData(DateTime date,double yValue1, double yValue2, double yValue3)
{
this.Date = date;
this.YValue1 = yValue1;
this.YValue2 = yValue2;
this.YValue3 = yValue3;
}
[JsonProperty("Date")]
public DateTime Date { get; set; }
[JsonProperty("YValue1")]
public Double YValue1 { get; set; }
[JsonProperty("YValue2")]
public Double YValue2 { get; set; }
[JsonProperty("YValue3")]
public Double YValue3 { get; set; }
} |