@@ -14,24 +14,24 @@ namespace FusionCharts.Charts
1414 /// @version: v3.6
1515 ///
1616 /// </summary>
17- public class Chart
17+ public class Chart : ICloneable
1818 {
1919 private Hashtable __CONFIG__ = null ;
20+ private static Hashtable __PARAMMAP__ = null ;
2021
2122 public enum ChartParameter
2223 {
23- type ,
24- id ,
25- width ,
26- height ,
24+ chartType ,
25+ chartId ,
26+ chartWidth ,
27+ chartHeight ,
2728 dataFormat ,
2829 dataSource ,
2930 renderAt ,
30- containerBackgroundColor ,
31- containerBackgroundOpacity
31+ bgColor ,
32+ bgOpacity
3233 }
3334
34-
3535 #region constractor methods
3636 /// <summary>
3737 ///
@@ -41,6 +41,23 @@ public Chart()
4141 __INIT ( ) ;
4242 }
4343
44+ private void SetParamsMap ( )
45+ {
46+ if ( __PARAMMAP__ == null )
47+ {
48+ __PARAMMAP__ = new Hashtable ( StringComparer . InvariantCultureIgnoreCase ) ;
49+ __PARAMMAP__ [ "chartType" ] = "type" ;
50+ __PARAMMAP__ [ "chartId" ] = "id" ;
51+ __PARAMMAP__ [ "chartWidth" ] = "width" ;
52+ __PARAMMAP__ [ "chartHeight" ] = "height" ;
53+ __PARAMMAP__ [ "dataFormat" ] = "dataFormat" ;
54+ __PARAMMAP__ [ "dataSource" ] = "dataSource" ;
55+ __PARAMMAP__ [ "renderAt" ] = "renderAt" ;
56+ __PARAMMAP__ [ "bgColor" ] = "containerBackgroundColor" ;
57+ __PARAMMAP__ [ "bgOpacity" ] = "containerBackgroundOpacity" ;
58+ }
59+
60+ }
4461
4562 /// <param name="chartType">The type of chart that you intend to plot</param>
4663 public Chart ( string chartType )
@@ -187,7 +204,7 @@ private string RenderChartALL()
187204 // if the user has provided renderAt then assume that the HTML container is already present in the page.
188205 if ( renderAt . Trim ( ) . Length == 0 )
189206 {
190- renderAt = chartId + "_Div " ;
207+ renderAt = chartId + "_div " ;
191208 // Now create the container div also.
192209 builder . AppendFormat ( "<div id='{0}' >" + Environment . NewLine , renderAt ) ;
193210 builder . Append ( "Chart..." + Environment . NewLine ) ;
@@ -212,6 +229,15 @@ private string RenderChartALL()
212229
213230 #region Public Methods
214231
232+ public object Clone ( )
233+ {
234+ Chart ChartClone = new Chart ( ) ;
235+ ChartClone . __CONFIG__ = ( Hashtable ) this . __CONFIG__ . Clone ( ) ;
236+ ChartClone . SetChartParameter ( "id" , ( ( Hashtable ) ChartClone . __CONFIG__ [ "params" ] ) [ "id" ] . ToString ( ) + "_clone" ) ;
237+
238+ return ChartClone ;
239+ }
240+
215241 /// <summary>
216242 /// Public method to generate html code for rendering chart
217243 /// This function assumes that you've already included the FusionCharts JavaScript class in your page
@@ -262,9 +288,12 @@ public string Render(string chartType, string chartId, string chartWidth, string
262288 /// <param name="value">Value of configuration</param>
263289 public void SetChartParameter ( ChartParameter param , object value )
264290 {
265- SetChartParameter ( param . ToString ( ) , value ) ;
291+
292+ SetChartParameter ( __PARAMMAP__ [ param . ToString ( ) ] . ToString ( ) , value ) ;
266293 }
267294
295+
296+
268297 /// <summary>
269298 /// This method set the data for the chart
270299 /// </summary>
@@ -310,20 +339,21 @@ private void SetChartParameter(string setting, object value)
310339 private void __INIT ( )
311340 {
312341 __CONFIG__ = new Hashtable ( StringComparer . InvariantCultureIgnoreCase ) ;
313- Hashtable param = new Hashtable ( StringComparer . InvariantCultureIgnoreCase ) ;
314- param [ "type" ] = "" ;
315- param [ "width" ] = "" ;
316- param [ "height" ] = "" ;
317- param [ "renderAt" ] = "" ;
318- param [ "dataSource" ] = "" ;
319- param [ "dataFormat" ] = "" ;
320- param [ "id" ] = "" ;
321- param [ "containerBackgroundColor" ] = "" ;
322- param [ "containerBackgroundOpacity" ] = "" ;
323-
324- __CONFIG__ [ "params" ] = param ;
325-
326- param = null ;
342+ Hashtable param = new Hashtable ( StringComparer . InvariantCultureIgnoreCase ) ;
343+ param [ "type" ] = "" ;
344+ param [ "width" ] = "" ;
345+ param [ "height" ] = "" ;
346+ param [ "renderAt" ] = "" ;
347+ param [ "dataSource" ] = "" ;
348+ param [ "dataFormat" ] = "" ;
349+ param [ "id" ] = Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "_" ) ;
350+ param [ "containerBackgroundColor" ] = "" ;
351+ param [ "containerBackgroundOpacity" ] = "" ;
352+
353+ __CONFIG__ [ "params" ] = param ;
354+
355+ param = null ;
356+ SetParamsMap ( ) ;
327357 }
328358
329359
@@ -368,7 +398,7 @@ private string fc_encodeJSON(Hashtable json, bool enclosed)
368398 }
369399 else if ( ds . Key . ToString ( ) . Equals ( "renderAt" ) )
370400 {
371- strjson = strjson + Environment . NewLine + "\" renderAt\" : \" " + ( ( Hashtable ) json ) [ "id" ] . ToString ( ) + "_Div \" , " ;
401+ strjson = strjson + Environment . NewLine + "\" renderAt\" : \" " + ( ( Hashtable ) json ) [ "id" ] . ToString ( ) + "_div \" , " ;
372402 }
373403 }
374404 // remove ending comma
@@ -392,6 +422,7 @@ private Hashtable GetConfigurationGroup(string setting)
392422 }
393423
394424 #endregion
425+
395426 }
396427}
397428
0 commit comments