با سلام
من برای رسم نمودار از لینک زیر استفاده کرده ام
https://dotnethighcharts.codeplex.com/
در اکشن مربوطه کد زیر را وارد کرده ام
using DotNet.Highcharts;
using DotNet.Highcharts.Options;
using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Helpers;
using Point = DotNet.Highcharts.Options.Point;
public ActionResult DataLabels()
{
if (Session["UserName"] == null)
return RedirectToAction("Login", "Home");
var transactionCounts = new List<TransactionCount> {
new TransactionCount(){ MonthName="January", Count=30},
new TransactionCount(){ MonthName="February", Count=40},
new TransactionCount(){ MonthName="March", Count=4},
new TransactionCount(){ MonthName="April", Count=35}
};
//modify data type to make it of array type
var xDataMonths = transactionCounts.Select(i => i.MonthName).ToArray();
var yDataCounts = transactionCounts.Select(i => new object[] { i.Count }).ToArray();
//instanciate an object of the Highcharts type
var chart = new Highcharts("chart")
//define the type of chart
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
//overall Title of the chart
.SetTitle(new Title { Text = "Incoming Transacions per hour" })
//small label below the main Title
.SetSubtitle(new Subtitle { Text = "Accounting" })
//load the X values
.SetXAxis(new XAxis { Categories = xDataMonths })
//set the Y title
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Number of Transactions" } })
.SetTooltip(new Tooltip
{
Enabled = true,
Formatter = @"function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y; }"
})
.SetPlotOptions(new PlotOptions
{
Line = new PlotOptionsLine
{
DataLabels = new PlotOptionsLineDataLabels
{
Enabled = true
},
EnableMouseTracking = false
}
})
//load the Y values
.SetSeries(new[]
{
new Series {Name = "Hour", Data = new Data(yDataCounts)},
//you can add more y data to create a second line
// new Series { Name = "Other Name", Data = new Data(OtherData) }
});
return View(chart);
}
ودر ویو مربوطه هم کد زیر را
@{
ViewBag.Title = "DataLabels";
Layout = "~/Views/Shared/_Home.cshtml";
}
@model DotNet.Highcharts.Highcharts
<h2>DataLabels</h2>
@(Model)
ولی نمودار به من نمایش داده نمی شود
در ضمن لینک زیر را هم مطالعه کرده ام
http://barnamenevisan.org/Articles/Article2873.html
دلیل اینکه نمایش نمی دهد چیست
موقعی که پیج لود میشه به این خطا برخورد کردم
مشکل حل شد
فایل مربوط به جاوا اسکریپت را من در پایین صفحه قرار داده بودم که وقتی به بالای صفحه انتقال دادم مشکل رفع شد
<script src="~/Scripts/Highcharts-4.0.1/js/highcharts.js"></script>
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)