Hi,
I want to export the data chart, but it don't work.
I'm implemented in accordance with Example.
Please teach me what is bad,
also let me know if there is an example to other.
* Export Chart Example
-------------------------------------------------------------------------------
View
-------------------------------------------------------------------------------
<button onclick="download()">down load</button>
<div id="chart"></div>
<script>
$(function ($) {
$("#chart").ejChart({
"exportSettings": {
"action": "ExportChart",
"mode" : "server",
"type" : "xlsx"
}
});
});
function download() {
$("#chart").ejChart("export");
}
</script>
-------------------------------------------------------------------------------
Controller
-------------------------------------------------------------------------------
public void ExportChart(string Data, string ChartModel)
{
ChartProperties obj = ConvertChartObject(ChartModel);
string type = obj.ExportSettings.Type.ToString().ToLower();
string fileName = obj.ExportSettings.FileName;
string orientation = obj.ExportSettings.Orientation.ToString();
List<KeyValuePair<string, object>> chartData = new List<KeyValuePair<string, object>>();
chartData.Add(new KeyValuePair<string, object>("John", 10));
chartData.Add(new KeyValuePair<string, object>("Jake", 20));
ExcelExport exp = new ExcelExport();
exp.Export(obj, (IEnumerable<KeyValuePair<string, object>>)chartData, fileName + ".xlsx", ExcelVersion.Excel2010, null, null);
}
private ChartProperties ConvertChartObject(string ChartModel)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable<KeyValuePair<string, object>> div = (IEnumerable<KeyValuePair<string, object>>)serializer.Deserialize(ChartModel, typeof(IEnumerable<KeyValuePair<string, object>>));
ChartProperties chartProp = new ChartProperties();
foreach (KeyValuePair<string, object> ds in div)
{
var property = chartProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (property != null)
{
Type type = property.PropertyType;
string serialize = serializer.Serialize(ds.Value);
object value = serializer.Deserialize(serialize, type);
property.SetValue(chartProp, value, null);
}
}
return chartProp;
}