ID | Value |
1 | 23 |
2 | 45 |
3 | 15 |
4 | 26 |
5 | 37 |
11 | 58 |
12 | 62 |
13 | 35 |
14 | 27 |
15 | 44 |
[C#]
List<ChartData> list = new List<ChartData>();
DataTable dt = new DataTable();
// Read the text file here//
using (System.IO.TextReader tr = File.OpenText(Server.MapPath(@"~\App_Data\data.txt")))
{
string line;
while ((line = tr.ReadLine()) != null)
{
string[] items = line.Trim().Split(',');
if (dt.Columns.Count == 0)
{
for (int i = 0; i < items.Length; i++)
dt.Columns.Add(new DataColumn("Column" + i, typeof(string)));
}
dt.Rows.Add(items);
}
}
//store the values in list from data table
foreach (DataRow dr in dt.Rows)
{
ChartData data = new ChartData();
data.Xvalue = Convert.ToDouble(dr.ItemArray[0]);
data.YValue1 = Convert.ToDouble(dr.ItemArray[1]);
list.Add(data);
}
// bind the data source to the here //
this.Chart1.DataSource = list;
this.Chart1.DataBind();
[JS]
function preRender(sender) { // OnClientPreRender event triggered
var points = sender.model.series[0].points;
var newPoints = [];
var currentPoint = [];
for (var i = 0; i < points.length; i++)
newPoints.push(points[i].x);
var newPoints = newPoints.sort(function (a, b) { return a - b });
var minPoint = Math.min.apply(null, newPoints);
var maxPoint = Math.max.apply(null, newPoints);
for (var j = minPoint; j < maxPoint; j++) {
var isPoint = $.inArray(j, newPoints);
if (isPoint < 0) {
var randomNum = getRandomArbitrary(10, 100);
points.push({ x: j, y: randomNum, isEmpty: true, visible: false, YValues: {} });
var yPoint = points[points.length - 1].YValues = [];
yPoint.push(randomNum);
}
}
sender.model.series[0].points = points.sort(function (a, b) { return a.x - b.x; });
} |