score:2
Accepted answer
class Program
{
static void Main(string[] args)
{
var ro = new RootObject();
ro.AddRow(1, "Name1", 2015, 10, 4);
ro.AddRow(1, "Name1", 2015, 11, 5);
ro.AddRow(1, "Name1", 2015, 12, 6);
ro.AddRow(2, "Name2", 2015, 10, 6);
ro.AddRow(2, "Name2", 2015, 11, 7);
ro.AddRow(2, "Name2", 2015, 12, 8);
ro.AddRow(3, "Name3", 2015, 10, 35);
ro.AddRow(3, "Name3", 2015, 11, 7);
ro.AddRow(3, "Name3", 2015, 12, 8);
string output = JsonConvert.SerializeObject(ro);
Console.WriteLine(output);
//Output:
//{
// "categories":[10,11,12],
// "series":[
// {"name":"Name1","data":[4,5,6]},
// {"name":"Name2","data":[6,7,8]},
// {"name":"Name3","data":[35,7,8]}]
//}
Console.ReadKey();
}
public class RootObject
{
public RootObject()
{
categories = new List<int>();
series = new List<Series>();
}
public void AddRow(int id, string name, int year, int month, int data)
{
if (!categories.Contains(month))
{
categories.Add(month);
}
var serie = series.FirstOrDefault(x => x.name == name);
if (serie == null)
{
serie = new Series(name);
series.Add(serie);
}
serie.data.Add(data);
}
public List<int> categories { get; set; }
public List<Series> series { get; set; }
}
public class Series
{
public Series(string _name)
{
name = _name;
data = new List<int>();
}
public string name { get; set; }
public List<int> data { get; set; }
}
}
Source: stackoverflow.com
Related Query
- Data Conversion from SQL, C# with Linq to JSON for Highcharts Line chart
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Add dynamic data to line chart from mysql database with highcharts
- HighCharts populate Pie Chart with data from SQL Database
- Highcharts chart dynamic json data from sql
- Highcharts to display area range and line chart with data from a CSV file
- how to make chart real time with 2 line and get data from php with highcharts
- Produce highcharts multiple line chart from JSON / MySQL data
- Passing data from PHP array to Highcharts chart with JSON
- Highcharts (highcharts-ng) with ng-repeat worked, But need to pass the data for each chart from the attributes
- Highcharts data from Google spreadsheet show line chart for one series
- Reload chart data via JSON with Highcharts
- Formatting JSON Data with ColdFusion for HighCharts
- How to format my json data for stack column chart in HighCharts
- Splitted bar chart for paired data with highcharts
- Formatting JSON from a Pandas data frame for Highcharts within a Django template
- Retrieving JSON data for Highcharts with multiple series?
- Highcharts add point to line chart with json
- Extracting data from a JSON call to a Postgres table for use in Highcharts (without PHP)
- Highcharts polar chart wind rose data from JSON
- highcharts example for using data from database with mvc
- Returning JSON file with cURL to use data in a HighCharts stock chart
- Issue with JSON data encoded from the server, not able to plot the chart
- Highcharts display label for pie chart using html table as data source
- HighCharts column chart populated with series data from a function
- Highcharts Sparkline chart with dynamic data for table -Angular js
- Plotting Highcharts Chart from multiple data points in json
- Highcharts combination chart from JSON data
- Highcharts column chart with data from mongodb
- Set HighCharts data from JSON string with setData() function
More Query from same tag
- How can i avoid congestion between x and y axis in my graph with highcharts?
- Highcharts - draw path on chart with datetime axis
- Amplify range of selection into error bar series
- Javascript setInterval/setTimeout not working when browser tab not focused
- Synchronize two highstock charts, same rangeSelector across two tabs
- how to show data label on mouse over in highcharts?
- Non-fixed svg height? My pie charts have different size even though svg width and pie size are identical. Svg height is fixed, how do i unfix it?
- Error in highcharts-export-server with expressjs
- How to use a react component as the label in Highcharts?
- how to select a button in highcharts-range selector row and click
- Highcharts network graph custom link labels
- Tickinterval of week,month,year in highcharts area spline chart
- Retrieving JSON data for Highcharts with multiple series?
- web interface using jQuery for Java application
- How to trigger legend click event on outside when using Highchart and no using JQuery
- export.highcharts.com bug? Changing order of series.index values not reflected in exported pics
- Highchart Annotation Connector
- Highcharts stacked bar with datetime, not able to set start date
- Date not displaying correctly on x-axis in High Stock Charts
- Highcharts: Is it possible to have separate plotOptions for each series?
- Set a Different Color Per Region/Province in a Country
- Benchmarking HighCharts, D3 and Canvas plotting
- how to get last value shown yAxis highcharts in current version in a simple way?
- Highcharts X-range. Columns of maximum height
- How to create legend for Plotlines with Highstock of Highcharts?
- Bar highchart just shows one value of my array
- Highcharts - with datetime axis labels overlap
- Highcharts loses it's dateRange values after refresh on IE<=9 and Chrome
- Highcharts: Render the bar chart from the bottom
- Highcharts: custom datalabel for bar chart. Format in PlotOptions not working