Below is my code to get the values,
List<object> modified_listofstrings = new List<object>();
List<string> p_Name = new List<string>();
List<string> s_Name = new List<string>();
System.Web.Script.Serialization.JavaScriptSerializer jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();
for (int i = 0; i < id_series_before_offset.Count; i++)
{
var xmlAttributeCollection = id_series_before_offset[i].Attributes;
if (xmlAttributeCollection != null)
{
var seriesid = xmlAttributeCollection["id"];
xmlActions_id[i] = seriesid.Value;
resulted_series_id = seriesid.Value;
series_name = Client.GetAttributeAsString(sessionId, resulted_series_id, "name", "");
s_Name.Add(series_name);----// Contains Target,Alarm,Actual
// Forloop for PeriodId and It's Value
var value = Read_XML_Before_Offset.SelectNodes("//measure.values/series[" + (i + 1) + "]/value");
var xmlActions = new string[value.Count];// for periodname
var xmlActionsone = new string[value.Count]; // for period value
for (int j = 0; j < value.Count; j++)
{
var xmlAttributeCollection_for_period = value[j].Attributes;
if (xmlAttributeCollection_for_period != null)
{
if (i == 0)
{
var periodid = xmlAttributeCollection_for_period["periodid"];
xmlActions[j] = periodid.Value;
period_final_id = periodid.Value;
period_name = Client.GetAttributeAsString(sessionId, periodid.Value, "name", "");
p_Name.Add(period_name);
}
var action = xmlAttributeCollection_for_period["value"];
xmlActionsone[j] = action.Value;
period_final_value = float.Parse(action.Value);
p_Value.Add(period_final_value);
}
}
}
}
var obj_series = new
{
name = s_Name,-------// I want here to have multiple series
data = p_Value------// values should belongs to respective series
};
var series = new[] { obj_series };
var obj_categories = new
{
categories = p_Name
};
var xAxis = new[] { obj_categories };
var chart = new
{
Type = read_ChartType
};
var obj_legend = new
{
layout,
floating,
backgroundColor,
align,
verticalAlign,
y,
x,
};
var legend = new[] { obj_legend };
var obj4 = new { legend = new[] { obj_legend }, chart, series, xAxis };
modified_listofstrings.Add(obj4);
jSearializer.Serialize(modified_listofstrings);
and the output I get is,
{
"legend":[{"layout":"vertical","floating":"true","backgroundColor":"#FFFFFF","align":"right",
"verticalAlign":"top","y":"60","x":"-60"}],
"chart":{"Type":"line"},
"series":[{"name":["01. Target","02. Alarm","03. Actual"],
"data":[14,14,14,14,18,18,18,18,17,15,13,12]}],
"xAxis":[{"categories":["Q1 / 2013","Q2 / 2013","Q3 / 2013","Q4 / 2013"]}]}
but what I expect data is as follows,
{"legend": [{"layout":"vertical","floating":"true","backgroundColor":"#FFFFFF","align":"right","verticalAlign":"top","y":"60","x":"-60"}],
"chart":{"Type":"line"},
"series":[{"name":"01. Target","data":[14,14,14,14]},{"name":"02. Alarm","data":[18,18,18,18]},{"name":"03. Actual","data":[17,15,13,12]}],
"xAxis":[{"categories":["Q1 / 2013","Q2 / 2013","Q3 / 2013","Q4 / 2013"]}]}
How can I get loop through list of s_Name and p_Value
I am not able to get the solution,any help will be greatly appreciated,
See Question&Answers more detail:
os