using System; using System.Text; using System.Collections.Generic; using FusionCharts.Charts; public partial class FirstChart : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //store label-value pair var dataValuePair = new List>(); dataValuePair.Add(new KeyValuePair("Venezuela", 290)); dataValuePair.Add(new KeyValuePair("Saudi", 260)); dataValuePair.Add(new KeyValuePair("Canada", 180)); dataValuePair.Add(new KeyValuePair("Iran", 140)); dataValuePair.Add(new KeyValuePair("Russia", 115)); dataValuePair.Add(new KeyValuePair("UAE", 100)); dataValuePair.Add(new KeyValuePair("US", 30)); dataValuePair.Add(new KeyValuePair("China", 30)); StringBuilder jsonData = new StringBuilder(); StringBuilder data = new StringBuilder(); // store chart config name-config value pair Dictionary chartConfig = new Dictionary(); chartConfig.Add("caption", "Countries With Most Oil Reserves [2017-18]"); chartConfig.Add("subCaption", "In MMbbl = One Million barrels"); chartConfig.Add("xAxisName", "Country"); chartConfig.Add("yAxisName", "Reserves (MMbbl)"); chartConfig.Add("numberSuffix", "k"); chartConfig.Add("theme", "fusion"); // json data to use as chart data source jsonData.Append("{'chart':{"); foreach (var config in chartConfig) { jsonData.AppendFormat("'{0}':'{1}',", config.Key, config.Value); } jsonData.Replace(",", "},", jsonData.Length - 1, 1); // build data object from label-value pair data.Append("'data':["); foreach (KeyValuePair pair in dataValuePair) { data.AppendFormat("{{'label':'{0}','value':'{1}'}},", pair.Key, pair.Value); } data.Replace(",", "]", data.Length - 1, 1); jsonData.Append(data.ToString()); jsonData.Append("}"); //Create chart instance // charttype, chartID, width, height, data format, data Chart chart = new Chart("column2d", "first_chart", "800", "550", "json", jsonData.ToString()); Literal1.Text = chart.Render(); } }