Sunday 15 July 2012

.net - c# DotNet.Highcharts switch statement -



.net - c# DotNet.Highcharts switch statement -

new c# , struggling ef , trying perform switch/case within foreach loop. want alter info query number string.

the data(key) query 1 2 3. there way of doing work?

if (selectquestion.selectedvalue == "1") { var info = db.tbl_complaints_data .where(d => d.organisation_id == o.organisation_id && d.service == site && d.date.month == month && d.q1 != null) .groupby(d => d.q1) .select(d => new { q1 = d.key, total = d.count() }); var segment = new list<object[]>(); foreach (var d in data) { segment.add(new object[] { switch (d.q1.tostring()) { case "1": d.q1.tostring() = "your care"; break; case "2": d.q1.tostring() = "another's care [friend or relative]"; break; case "3": d.q1.tostring() = "other type of complaint"; break; }, d.total }); } render_piechart(segment);

this pie chart if there interest.

protected void render_piechart(list<object[]> pdata) { dotnet.highcharts.highcharts chart = new dotnet.highcharts.highcharts("chart") .initchart(new chart { defaultseriestype = charttypes.pie }) .settitle(new title { text = selectquestion.selecteditem.text }) .setsubtitle(new subtitle { text = selectmonth.selecteditem.text }) .setseries(new[] { new series { info = new dotnet.highcharts.helpers.data(pdata.toarray()) } }) .setcredits(new credits { enabled = false }); ltrchart.text = chart.tohtmlstring(); }`

any help or advice appreciated.

the compiler telling code wrong:

you can't switch within new object[] init --> invalid look term 'switch' you can't assign variable tostring() --> the left-hand side of assignment must variable, property or indexer

rewrite as:

var segment = new list<object[]>(); foreach (var d in data) { string q1string = "unknown"; switch (d.q1) { case 1: q1string = "your care"; break; case 2: q1string = "another's care [friend or relative]"; break; case 3: q1string = "other type of complaint"; break; default: break; } segment.add(new object[] { q1string, d.total }); }

c# .net highcharts

No comments:

Post a Comment