ChartWinControl.cs 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: Main windows forms chart control class.
  6. //
  7. using System;
  8. using System.Windows.Forms;
  9. using System.Collections;
  10. using System.ComponentModel;
  11. using System.ComponentModel.Design;
  12. using System.ComponentModel.Design.Serialization;
  13. using System.Diagnostics.CodeAnalysis;
  14. using System.Drawing;
  15. using System.Drawing.Design;
  16. using System.Drawing.Imaging;
  17. using System.Globalization;
  18. using System.IO;
  19. using System.Reflection;
  20. using FastReport.DataVisualization.Charting.Borders3D;
  21. using FastReport.DataVisualization.Charting.ChartTypes;
  22. using FastReport.DataVisualization.Charting.Data;
  23. using FastReport.DataVisualization.Charting.Formulas;
  24. using FastReport.DataVisualization.Charting.Utilities;
  25. namespace FastReport.DataVisualization.Charting
  26. {
  27. #region Enumerations
  28. /// <summary>
  29. /// Specifies the format of the image
  30. /// </summary>
  31. public enum ChartImageFormat
  32. {
  33. /// <summary>
  34. /// Gets the Joint Photographic Experts Group (JPEG) image format.
  35. /// </summary>
  36. Jpeg,
  37. /// <summary>
  38. /// Gets the W3C Portable Network Graphics (PNG) image format.
  39. /// </summary>
  40. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Png")]
  41. Png,
  42. /// <summary>
  43. /// Gets the bitmap image format (BMP).
  44. /// </summary>
  45. Bmp,
  46. /// <summary>
  47. /// Gets the Tag Image File Format (TIFF) image format.
  48. /// </summary>
  49. Tiff,
  50. /// <summary>
  51. /// Gets the Graphics Interchange Format (GIF) image format.
  52. /// </summary>
  53. Gif,
  54. /// <summary>
  55. /// Gets the Enhanced Meta File (Emf) image format.
  56. /// </summary>
  57. Emf,
  58. /// <summary>
  59. /// Enhanced Meta File (EmfDual) image format.
  60. /// </summary>
  61. EmfDual,
  62. /// <summary>
  63. /// Enhanced Meta File (Emf+) image format.
  64. /// </summary>
  65. EmfPlus,
  66. }
  67. #endregion
  68. /// <summary>
  69. /// Chart windows forms control
  70. /// </summary>
  71. [SRDescription("DescriptionAttributeChart_Chart")]
  72. #if DESIGNER
  73. [ToolboxBitmap(typeof(Chart), "ChartControl.ico")]
  74. [Designer(typeof(ChartWinDesigner))]
  75. [DesignerSerializer(typeof(ChartWinDesignerSerializer), typeof(CodeDomSerializer))]
  76. #endif
  77. [DisplayNameAttribute("Chart")]
  78. public class Chart : System.Windows.Forms.Control, ISupportInitialize, IDisposable
  79. {
  80. #region Control fields
  81. /// <summary>
  82. /// Determines whether or not to show debug markings in debug mode. For internal use.
  83. /// </summary>
  84. internal bool ShowDebugMarkings = false;
  85. // Chart services components
  86. private ChartTypeRegistry _chartTypeRegistry = null;
  87. private BorderTypeRegistry _borderTypeRegistry = null;
  88. private CustomPropertyRegistry _customAttributeRegistry = null;
  89. private DataManager _dataManager = null;
  90. internal ChartImage chartPicture = null;
  91. private ImageLoader _imageLoader = null;
  92. internal ServiceContainer serviceContainer = null;
  93. private ChartSerializer _chartSerializer = null;
  94. private PrintingManager _printingManager = null;
  95. // Selection class
  96. internal Selection selection = null;
  97. // Named images collection
  98. private NamedImagesCollection _namedImages = null;
  99. // Formula registry servise component
  100. private FormulaRegistry _formulaRegistry = null;
  101. // Indicates that control invalidation is temporary disabled
  102. internal bool disableInvalidates = false;
  103. // Indicates that chart is serializing the data
  104. internal bool serializing = false;
  105. // Detailed serialization status which allows not only to determine if serialization
  106. // is curently in process but also check if we are saving, loading or resetting the chart.
  107. internal SerializationStatus serializationStatus = SerializationStatus.None;
  108. // Bitmap used for double buffering chart painting
  109. internal Bitmap paintBufferBitmap = null;
  110. // Graphics of the double buffered bitmap
  111. internal IGraphics paintBufferBitmapGraphics = null;
  112. // Indicates that only chart area cursor/selection must be drawn during the next paint event
  113. internal bool paintTopLevelElementOnly = false;
  114. // Indicates that some chart properties where changed (used for painting)
  115. internal bool dirtyFlag = true;
  116. // Chart default cursor
  117. internal System.Windows.Forms.Cursor defaultCursor = Cursors.Default;
  118. // Keywords registry
  119. private KeywordsRegistry _keywordsRegistry = null;
  120. // Horizontal rendering resolution.
  121. static internal double renderingDpiX = 96.0;
  122. // Vertical rendering resolution.
  123. static internal double renderingDpiY = 96.0;
  124. #endregion
  125. #region Component Designer generated code
  126. /// <summary>
  127. /// Required method for Designer support - do not modify
  128. /// the contents of this method with the code editor.
  129. /// </summary>
  130. private void InitializeComponent()
  131. {
  132. }
  133. #endregion
  134. #region Control constructors
  135. /// <summary>
  136. /// Chart control constructor.
  137. /// </summary>
  138. public Chart()
  139. {
  140. //*******************************************************
  141. //** Check control license
  142. //*******************************************************
  143. //*********************************************************
  144. //** Set control styles
  145. //*********************************************************
  146. this.SetStyle(ControlStyles.ResizeRedraw, true);
  147. //this.SetStyle(ControlStyles.Opaque, true);
  148. this.SetStyle(ControlStyles.UserPaint, true);
  149. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  150. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  151. this.SetStyle(ControlStyles.Selectable, true);
  152. // NOTE: Fixes issue #4475
  153. this.SetStyle(ControlStyles.DoubleBuffer, true);
  154. // This is necessary to raise focus event on chart mouse click.
  155. this.SetStyle(ControlStyles.UserMouse, true);
  156. //*********************************************************
  157. //** Create services
  158. //*********************************************************
  159. serviceContainer = new ServiceContainer();
  160. _chartTypeRegistry = new ChartTypeRegistry();
  161. _borderTypeRegistry = new BorderTypeRegistry();
  162. _customAttributeRegistry = new CustomPropertyRegistry();
  163. _keywordsRegistry = new KeywordsRegistry();
  164. _dataManager = new DataManager(serviceContainer);
  165. _imageLoader = new ImageLoader(serviceContainer);
  166. chartPicture = new ChartImage(serviceContainer);
  167. _chartSerializer = new ChartSerializer(serviceContainer);
  168. _printingManager = new PrintingManager(serviceContainer);
  169. _formulaRegistry = new FormulaRegistry();
  170. // Add services to the service container
  171. serviceContainer.AddService(typeof(Chart), this); // Chart Control
  172. serviceContainer.AddService(_chartTypeRegistry.GetType(), _chartTypeRegistry);// Chart types registry
  173. serviceContainer.AddService(_borderTypeRegistry.GetType(), _borderTypeRegistry);// Border types registry
  174. serviceContainer.AddService(_customAttributeRegistry.GetType(), _customAttributeRegistry);// Custom attribute registry
  175. serviceContainer.AddService(_dataManager.GetType(), _dataManager); // Data Manager service
  176. serviceContainer.AddService(_imageLoader.GetType(), _imageLoader); // Image Loader service
  177. serviceContainer.AddService(chartPicture.GetType(), chartPicture); // Chart image service
  178. serviceContainer.AddService(_chartSerializer.GetType(), _chartSerializer); // Chart serializer service
  179. serviceContainer.AddService(_printingManager.GetType(), _printingManager); // Printing manager service
  180. serviceContainer.AddService(_formulaRegistry.GetType(), _formulaRegistry); // Formula modules service
  181. serviceContainer.AddService(_keywordsRegistry.GetType(), _keywordsRegistry); // Keywords registry
  182. // Initialize objects
  183. _dataManager.Initialize();
  184. // Register known chart types
  185. _chartTypeRegistry.Register( ChartTypeNames.Bar, typeof(BarChart));
  186. _chartTypeRegistry.Register( ChartTypeNames.Column, typeof(ColumnChart));
  187. _chartTypeRegistry.Register( ChartTypeNames.Point, typeof(PointChart));
  188. _chartTypeRegistry.Register( ChartTypeNames.Bubble, typeof(BubbleChart));
  189. _chartTypeRegistry.Register( ChartTypeNames.Line, typeof(LineChart));
  190. _chartTypeRegistry.Register( ChartTypeNames.Spline, typeof(SplineChart));
  191. _chartTypeRegistry.Register( ChartTypeNames.StepLine, typeof(StepLineChart));
  192. _chartTypeRegistry.Register( ChartTypeNames.Area, typeof(AreaChart));
  193. _chartTypeRegistry.Register( ChartTypeNames.SplineArea, typeof(SplineAreaChart));
  194. _chartTypeRegistry.Register( ChartTypeNames.StackedArea, typeof(StackedAreaChart));
  195. _chartTypeRegistry.Register( ChartTypeNames.Pie, typeof(PieChart));
  196. _chartTypeRegistry.Register( ChartTypeNames.Stock, typeof(StockChart));
  197. _chartTypeRegistry.Register( ChartTypeNames.Candlestick, typeof(CandleStickChart));
  198. _chartTypeRegistry.Register( ChartTypeNames.Doughnut, typeof(DoughnutChart));
  199. _chartTypeRegistry.Register( ChartTypeNames.StackedBar, typeof(StackedBarChart));
  200. _chartTypeRegistry.Register( ChartTypeNames.StackedColumn, typeof(StackedColumnChart));
  201. _chartTypeRegistry.Register( ChartTypeNames.OneHundredPercentStackedColumn, typeof(HundredPercentStackedColumnChart));
  202. _chartTypeRegistry.Register( ChartTypeNames.OneHundredPercentStackedBar, typeof(HundredPercentStackedBarChart));
  203. _chartTypeRegistry.Register( ChartTypeNames.OneHundredPercentStackedArea, typeof(HundredPercentStackedAreaChart));
  204. _chartTypeRegistry.Register(ChartTypeNames.Range, typeof(RangeChart));
  205. _chartTypeRegistry.Register(ChartTypeNames.SplineRange, typeof(SplineRangeChart));
  206. _chartTypeRegistry.Register(ChartTypeNames.RangeBar, typeof(RangeBarChart));
  207. _chartTypeRegistry.Register(ChartTypeNames.Radar, typeof(RadarChart));
  208. _chartTypeRegistry.Register(ChartTypeNames.RangeColumn, typeof(RangeColumnChart));
  209. _chartTypeRegistry.Register(ChartTypeNames.ErrorBar, typeof(ErrorBarChart));
  210. _chartTypeRegistry.Register(ChartTypeNames.BoxPlot, typeof(BoxPlotChart));
  211. _chartTypeRegistry.Register(ChartTypeNames.Renko, typeof(RenkoChart));
  212. _chartTypeRegistry.Register(ChartTypeNames.ThreeLineBreak, typeof(ThreeLineBreakChart));
  213. _chartTypeRegistry.Register(ChartTypeNames.Kagi, typeof(KagiChart));
  214. _chartTypeRegistry.Register(ChartTypeNames.PointAndFigure, typeof(PointAndFigureChart));
  215. _chartTypeRegistry.Register(ChartTypeNames.Polar, typeof(PolarChart));
  216. _chartTypeRegistry.Register(ChartTypeNames.FastLine, typeof(FastLineChart));
  217. _chartTypeRegistry.Register(ChartTypeNames.Funnel, typeof(FunnelChart));
  218. _chartTypeRegistry.Register(ChartTypeNames.Pyramid, typeof(PyramidChart));
  219. _chartTypeRegistry.Register(ChartTypeNames.FastPoint, typeof(FastPointChart));
  220. // Register known formula modules
  221. _formulaRegistry.Register(SR.FormulaNamePriceIndicators, typeof(PriceIndicators));
  222. _formulaRegistry.Register(SR.FormulaNameGeneralTechnicalIndicators,typeof(GeneralTechnicalIndicators));
  223. _formulaRegistry.Register(SR.FormulaNameTechnicalVolumeIndicators, typeof(VolumeIndicators));
  224. _formulaRegistry.Register(SR.FormulaNameOscillator, typeof(Oscillators));
  225. _formulaRegistry.Register(SR.FormulaNameGeneralFormulas, typeof(GeneralFormulas));
  226. _formulaRegistry.Register(SR.FormulaNameTimeSeriesAndForecasting, typeof(TimeSeriesAndForecasting));
  227. _formulaRegistry.Register(SR.FormulaNameStatisticalAnalysis, typeof(StatisticalAnalysis));
  228. // Register known 3D border types
  229. _borderTypeRegistry.Register("Emboss", typeof(EmbossBorder));
  230. _borderTypeRegistry.Register("Raised", typeof(RaisedBorder));
  231. _borderTypeRegistry.Register("Sunken", typeof(SunkenBorder));
  232. _borderTypeRegistry.Register("FrameThin1", typeof(FrameThin1Border));
  233. _borderTypeRegistry.Register("FrameThin2", typeof(FrameThin2Border));
  234. _borderTypeRegistry.Register("FrameThin3", typeof(FrameThin3Border));
  235. _borderTypeRegistry.Register("FrameThin4", typeof(FrameThin4Border));
  236. _borderTypeRegistry.Register("FrameThin5", typeof(FrameThin5Border));
  237. _borderTypeRegistry.Register("FrameThin6", typeof(FrameThin6Border));
  238. _borderTypeRegistry.Register("FrameTitle1", typeof(FrameTitle1Border));
  239. _borderTypeRegistry.Register("FrameTitle2", typeof(FrameTitle2Border));
  240. _borderTypeRegistry.Register("FrameTitle3", typeof(FrameTitle3Border));
  241. _borderTypeRegistry.Register("FrameTitle4", typeof(FrameTitle4Border));
  242. _borderTypeRegistry.Register("FrameTitle5", typeof(FrameTitle5Border));
  243. _borderTypeRegistry.Register("FrameTitle6", typeof(FrameTitle6Border));
  244. _borderTypeRegistry.Register("FrameTitle7", typeof(FrameTitle7Border));
  245. _borderTypeRegistry.Register("FrameTitle8", typeof(FrameTitle8Border));
  246. // Enable chart invalidating
  247. this.disableInvalidates = false;
  248. // Create selection object
  249. selection = new Selection(serviceContainer);
  250. // Create named images collection
  251. _namedImages = new NamedImagesCollection();
  252. // Hook up event handlers
  253. ChartAreas.NameReferenceChanged += new EventHandler<NameReferenceChangedEventArgs>(Series.ChartAreaNameReferenceChanged);
  254. ChartAreas.NameReferenceChanged += new EventHandler<NameReferenceChangedEventArgs>(Legends.ChartAreaNameReferenceChanged);
  255. ChartAreas.NameReferenceChanged += new EventHandler<NameReferenceChangedEventArgs>(Titles.ChartAreaNameReferenceChanged);
  256. ChartAreas.NameReferenceChanged += new EventHandler<NameReferenceChangedEventArgs>(Annotations.ChartAreaNameReferenceChanged);
  257. ChartAreas.NameReferenceChanged += new EventHandler<NameReferenceChangedEventArgs>(ChartAreas.ChartAreaNameReferenceChanged);
  258. Legends.NameReferenceChanged += new EventHandler<NameReferenceChangedEventArgs>(Series.LegendNameReferenceChanged);
  259. }
  260. #endregion
  261. #region Control painting methods
  262. /// <summary>
  263. /// Paint chart control.
  264. /// </summary>
  265. /// <param name="e">Paint event arguments.</param>
  266. protected override void OnPaint(PaintEventArgs e)
  267. {
  268. //*******************************************************
  269. //** Check control license
  270. // Disable invalidates
  271. this.disableInvalidates = true;
  272. //*******************************************************
  273. //** If chart background is transparent - draw without
  274. //** double buffering.
  275. //*******************************************************
  276. if(this.IsBorderTransparent() ||
  277. !this.BackColor.IsEmpty &&
  278. (this.BackColor == Color.Transparent || this.BackColor.A != 255) )
  279. {
  280. /* Unmerged change from project 'Chart-Win (net5.0-windows7.0)'
  281. Before:
  282. StandardGraphicsRenderer gr = new StandardGraphicsRenderer(e.Graphics, false);
  283. After:
  284. GdiGraphics gr = new StandardGraphicsRenderer(e.Graphics, false);
  285. */
  286. /* Unmerged change from project 'Chart-Win (netcoreapp3.0)'
  287. Before:
  288. StandardGraphicsRenderer gr = new StandardGraphicsRenderer(e.Graphics, false);
  289. After:
  290. GdiGraphics gr = new StandardGraphicsRenderer(e.Graphics, false);
  291. */
  292. FastReport.GdiGraphics gr = new FastReport.GdiGraphics(e.Graphics, false);
  293. // Draw chart directly on the graphics
  294. try
  295. {
  296. if(this.paintTopLevelElementOnly)
  297. {
  298. chartPicture.Paint(gr, false);
  299. }
  300. chartPicture.Paint(gr, this.paintTopLevelElementOnly);
  301. }
  302. catch(Exception)
  303. {
  304. // Draw exception method
  305. DrawException(gr);
  306. // Rethrow exception if not in design-time mode
  307. if(!this.DesignMode)
  308. {
  309. throw;
  310. }
  311. }
  312. }
  313. else
  314. {
  315. //*******************************************************
  316. //** If nothing was changed in the chart and last image is stored in the buffer
  317. //** there is no need to repaint the chart.
  318. //*******************************************************
  319. if(this.dirtyFlag || paintBufferBitmap == null)
  320. {
  321. // Get scaling component from the drawing graphics
  322. float scaleX = e.Graphics.Transform.Elements[0];
  323. float scaleY = e.Graphics.Transform.Elements[3];
  324. // Create offscreen buffer bitmap
  325. if(paintBufferBitmap == null ||
  326. paintBufferBitmap.Width < scaleX * ClientRectangle.Width ||
  327. paintBufferBitmap.Height < scaleY * ClientRectangle.Height)
  328. {
  329. if(paintBufferBitmap != null)
  330. {
  331. paintBufferBitmap.Dispose();
  332. paintBufferBitmapGraphics.Dispose();
  333. }
  334. // Create offscreen bitmap taking in consideration graphics scaling
  335. paintBufferBitmap = new Bitmap((int)(ClientRectangle.Width * scaleX), (int)(ClientRectangle.Height * scaleY), e.Graphics);
  336. paintBufferBitmapGraphics = new FastReport.GdiGraphics(paintBufferBitmap);
  337. paintBufferBitmapGraphics.ScaleTransform(scaleX, scaleY);
  338. }
  339. //*******************************************************
  340. //** Draw chart in bitmap buffer
  341. //*******************************************************
  342. try
  343. {
  344. chartPicture.Paint(paintBufferBitmapGraphics, this.paintTopLevelElementOnly);
  345. }
  346. catch(Exception)
  347. {
  348. // Draw exception method
  349. DrawException(paintBufferBitmapGraphics);
  350. // Rethrow exception if not in design-time mode
  351. if(!this.DesignMode)
  352. {
  353. throw;
  354. }
  355. }
  356. }
  357. //*******************************************************
  358. //** Push bitmap buffer forward into the screen
  359. //*******************************************************
  360. // Set drawing scale 1:1. Only persist the transformation from current matrix
  361. System.Drawing.Drawing2D.Matrix drawingMatrix = new System.Drawing.Drawing2D.Matrix();
  362. System.Drawing.Drawing2D.Matrix oldMatrix = e.Graphics.Transform;
  363. drawingMatrix.Translate(oldMatrix.OffsetX, oldMatrix.OffsetY);
  364. e.Graphics.Transform = drawingMatrix;
  365. // Draw image
  366. e.Graphics.DrawImage(paintBufferBitmap, 0, 0);
  367. e.Graphics.Transform = oldMatrix;
  368. }
  369. // Clears control dirty flag
  370. this.dirtyFlag = false;
  371. this.disableInvalidates = false;
  372. // Call base class
  373. base.OnPaint(e);
  374. //*******************************************************
  375. //** Check if smart client data must be loaded
  376. //*******************************************************
  377. }
  378. /// <summary>
  379. /// Paints control background.
  380. /// </summary>
  381. /// <param name="pevent">Event arguments.</param>
  382. protected override void OnPaintBackground(PaintEventArgs pevent)
  383. {
  384. this.disableInvalidates = true;
  385. //*********************************************************
  386. //** Check if chart back ground has a transparent color
  387. //*********************************************************
  388. bool transpBack = false;
  389. if(chartPicture.BackColor.A != 255 && chartPicture.BackColor != Color.Empty)
  390. {
  391. transpBack = true;
  392. }
  393. else if(chartPicture.BackImageTransparentColor.A != 255 &&
  394. chartPicture.BackImageTransparentColor != Color.Empty &&
  395. !String.IsNullOrEmpty(chartPicture.BackImage))
  396. {
  397. transpBack = true;
  398. }
  399. //*********************************************************
  400. //** If chart or chart border page colr has transparent color
  401. //*********************************************************
  402. bool transpBorder = this.IsBorderTransparent();
  403. if( transpBorder || transpBack)
  404. {
  405. Color oldBackColor = chartPicture.BackColor;
  406. if(transpBorder)
  407. {
  408. chartPicture.BackColor = Color.Transparent;
  409. }
  410. // Call base class
  411. base.OnPaintBackground(pevent);
  412. chartPicture.BackColor = oldBackColor;
  413. }
  414. this.disableInvalidates = false;
  415. }
  416. /// <summary>
  417. /// When user changes system color, the Chart redraws itself.
  418. /// </summary>
  419. /// <param name="e">Event arguments.</param>
  420. protected override void OnSystemColorsChanged(EventArgs e)
  421. {
  422. base.OnSystemColorsChanged(e);
  423. this.Invalidate();
  424. }
  425. /// <summary>
  426. /// Checks if border skins is enabled in the chart and it uses transparency in the page color
  427. /// </summary>
  428. /// <returns>True if transparency is used in the border.</returns>
  429. private bool IsBorderTransparent()
  430. {
  431. bool transpBorder = false;
  432. if(chartPicture.BorderSkin.SkinStyle != BorderSkinStyle.None)
  433. {
  434. if( chartPicture.BorderSkin.PageColor.A != 255 &&
  435. chartPicture.BorderSkin.PageColor != Color.Empty)
  436. {
  437. transpBorder = true;
  438. }
  439. if(chartPicture.BorderSkin.BackColor.A != 255 && chartPicture.BorderSkin.BackColor != Color.Empty)
  440. {
  441. transpBorder = true;
  442. }
  443. else if(chartPicture.BorderSkin.BackImageTransparentColor.A != 255 &&
  444. chartPicture.BorderSkin.BackImageTransparentColor != Color.Empty &&
  445. !String.IsNullOrEmpty(chartPicture.BorderSkin.BackImage))
  446. {
  447. transpBorder = true;
  448. }
  449. }
  450. return transpBorder;
  451. }
  452. /// <summary>
  453. /// Draws exception information at design-time.
  454. /// </summary>
  455. /// <param name="graphics">Chart graphics to use.</param>
  456. private void DrawException(IGraphics graphics)
  457. {
  458. // Fill background
  459. graphics.FillRectangle(Brushes.White, 0, 0, this.Width, this.Height);
  460. string addMessage = SR.ExceptionChartPreviewNotAvailable;
  461. // Get text rectangle
  462. RectangleF rect = new RectangleF(3, 3, this.Width-6, this.Height-6);
  463. // Draw exception text
  464. using (StringFormat format = new StringFormat())
  465. {
  466. format.Alignment = StringAlignment.Center;
  467. format.LineAlignment = StringAlignment.Center;
  468. using (Font font = new Font(FontCache.DefaultFamilyName, 8))
  469. {
  470. graphics.DrawString(addMessage, font, Brushes.Black, rect, format);
  471. }
  472. }
  473. }
  474. /// <summary>
  475. /// Forces the control to invalidate its client area and immediately redraw itself and any child controls.
  476. /// </summary>
  477. [
  478. EditorBrowsable(EditorBrowsableState.Never)
  479. ]
  480. public override void Refresh()
  481. {
  482. // Clear bitmap used to improve the performance of elements
  483. // like cursors and annotations
  484. // NOTE: Fixes issue #4157
  485. if(this.chartPicture.nonTopLevelChartBuffer != null)
  486. {
  487. this.chartPicture.nonTopLevelChartBuffer.Dispose();
  488. this.chartPicture.nonTopLevelChartBuffer = null;
  489. }
  490. this.dirtyFlag = true;
  491. #if ACCESSIBLE
  492. this.ResetAccessibilityObject();
  493. #endif
  494. base.Refresh();
  495. }
  496. /// <summary>
  497. /// Invalidates a specific region of the control and causes a paint message to be sent to the control.
  498. /// </summary>
  499. public new void Invalidate()
  500. {
  501. this.dirtyFlag = true;
  502. #if ACCESSIBLE
  503. this.ResetAccessibilityObject();
  504. #endif
  505. if (!this.disableInvalidates)
  506. {
  507. base.Invalidate(true);
  508. }
  509. // NOTE: Code below required for the Diagram integration. -AG
  510. if(!this.chartPicture.isSavingAsImage)
  511. {
  512. InvalidateEventArgs e = new InvalidateEventArgs(Rectangle.Empty);
  513. this.OnInvalidated(e);
  514. }
  515. }
  516. /// <summary>
  517. /// Invalidates a specific region of the control and causes a paint message to be sent to the control.
  518. /// </summary>
  519. public new void Invalidate(Rectangle rectangle)
  520. {
  521. this.dirtyFlag = true;
  522. #if ACCESSIBLE
  523. this.ResetAccessibilityObject();
  524. #endif
  525. if (!this.disableInvalidates)
  526. {
  527. base.Invalidate(rectangle);
  528. }
  529. // NOTE: Code below required for the Diagram integration. -AG
  530. if(!this.chartPicture.isSavingAsImage)
  531. {
  532. InvalidateEventArgs e = new InvalidateEventArgs(Rectangle.Empty);
  533. this.OnInvalidated(e);
  534. }
  535. }
  536. /// <summary>
  537. /// Updates chart cursor and range selection only.
  538. /// </summary>
  539. public void UpdateCursor()
  540. {
  541. // Set flag to redraw cursor/selection only
  542. this.paintTopLevelElementOnly = true;
  543. // Update chart cursor and range selection
  544. base.Update();
  545. // Clear flag to redraw cursor/selection only
  546. this.paintTopLevelElementOnly = false;
  547. }
  548. /// <summary>
  549. /// Updates chart annotations only.
  550. /// </summary>
  551. public void UpdateAnnotations()
  552. {
  553. // Set flag to redraw cursor/selection only
  554. this.paintTopLevelElementOnly = true;
  555. // Update chart cursor and range selection
  556. base.Update();
  557. // Clear flag to redraw cursor/selection only
  558. this.paintTopLevelElementOnly = false;
  559. }
  560. #endregion
  561. #region Control size and location properties/methods
  562. /// <summary>
  563. /// Returns default control size.
  564. /// </summary>
  565. protected override System.Drawing.Size DefaultSize
  566. {
  567. get
  568. {
  569. return new System.Drawing.Size(300, 300);
  570. }
  571. }
  572. /// <summary>
  573. /// Control location changed.
  574. /// </summary>
  575. /// <param name="e">Event arguments.</param>
  576. protected override void OnLocationChanged(EventArgs e)
  577. {
  578. // If chart or chart border page color has transparent color
  579. if((chartPicture.BackColor.A != 255 && chartPicture.BackColor != Color.Empty) ||
  580. (chartPicture.BorderSkin.SkinStyle != BorderSkinStyle.None &&
  581. chartPicture.BorderSkin.PageColor.A != 255 &&
  582. chartPicture.BorderSkin.PageColor != Color.Empty))
  583. {
  584. if(!this.disableInvalidates)
  585. {
  586. this.Invalidate();
  587. }
  588. }
  589. base.OnLocationChanged(e);
  590. }
  591. /// <summary>
  592. /// Control resized.
  593. /// </summary>
  594. /// <param name="e">Event arguments.</param>
  595. protected override void OnResize(EventArgs e)
  596. {
  597. chartPicture.Width = this.Size.Width;
  598. chartPicture.Height = this.Size.Height;
  599. this.dirtyFlag = true;
  600. #if ACCESSIBLE
  601. this.ResetAccessibilityObject();
  602. #endif
  603. base.OnResize(e);
  604. }
  605. /// <summary>
  606. /// Fires RightToLeftChanged event.
  607. /// </summary>
  608. /// <param name="e">Event Arguments</param>
  609. protected override void OnRightToLeftChanged(EventArgs e)
  610. {
  611. base.OnRightToLeftChanged(e);
  612. this.Invalidate();
  613. }
  614. #endregion
  615. #region Chart image saving methods
  616. /// <summary>
  617. /// Saves chart image into the file.
  618. /// </summary>
  619. /// <param name="imageFileName">Image file name</param>
  620. /// <param name="format">Image format.</param>
  621. public void SaveImage(string imageFileName, ChartImageFormat format)
  622. {
  623. // Check arguments
  624. if (imageFileName == null)
  625. throw new ArgumentNullException("imageFileName");
  626. // Create file stream for the specified file name
  627. FileStream fileStream = new FileStream(imageFileName, FileMode.Create);
  628. // Save into stream
  629. try
  630. {
  631. SaveImage(fileStream, format);
  632. }
  633. finally
  634. {
  635. // Close file stream
  636. fileStream.Close();
  637. }
  638. }
  639. /// <summary>
  640. /// Saves chart image into the file.
  641. /// </summary>
  642. /// <param name="imageFileName">Image file name</param>
  643. /// <param name="format">Image format.</param>
  644. public void SaveImage(string imageFileName, ImageFormat format)
  645. {
  646. // Check arguments
  647. if (imageFileName == null)
  648. throw new ArgumentNullException("imageFileName");
  649. if (format == null)
  650. throw new ArgumentNullException("format");
  651. // Create file stream for the specified file name
  652. FileStream fileStream = new FileStream(imageFileName, FileMode.Create);
  653. // Save into stream
  654. try
  655. {
  656. SaveImage(fileStream, format);
  657. }
  658. finally
  659. {
  660. // Close file stream
  661. fileStream.Close();
  662. }
  663. }
  664. /// <summary>
  665. /// Saves chart image into the stream.
  666. /// </summary>
  667. /// <param name="imageStream">Image stream.</param>
  668. /// <param name="format">Image format.</param>
  669. public void SaveImage(Stream imageStream, ImageFormat format)
  670. {
  671. // Check arguments
  672. if (imageStream == null)
  673. throw new ArgumentNullException("imageStream");
  674. if (format == null)
  675. throw new ArgumentNullException("format");
  676. // Indicate that chart is saved into the image
  677. this.chartPicture.isSavingAsImage = true;
  678. if(format == ImageFormat.Emf || format == ImageFormat.Wmf)
  679. {
  680. this.chartPicture.SaveIntoMetafile(imageStream, EmfType.EmfOnly);
  681. }
  682. else
  683. {
  684. // Get chart image
  685. Image chartImage = this.chartPicture.GetImage();
  686. // Save image into the file
  687. chartImage.Save(imageStream, format);
  688. // Dispose image
  689. chartImage.Dispose();
  690. }
  691. // Reset flag
  692. this.chartPicture.isSavingAsImage = false;
  693. }
  694. /// <summary>
  695. /// Saves chart image into the stream.
  696. /// </summary>
  697. /// <param name="imageStream">Image stream.</param>
  698. /// <param name="format">Image format.</param>
  699. public void SaveImage( Stream imageStream, ChartImageFormat format )
  700. {
  701. // Check arguments
  702. if (imageStream == null)
  703. throw new ArgumentNullException("imageStream");
  704. // Indicate that chart is saved into the image
  705. this.chartPicture.isSavingAsImage = true;
  706. if( format == ChartImageFormat.Emf ||
  707. format == ChartImageFormat.EmfPlus ||
  708. format == ChartImageFormat.EmfDual)
  709. {
  710. EmfType emfType = EmfType.EmfOnly;
  711. if(format == ChartImageFormat.EmfDual)
  712. {
  713. emfType = EmfType.EmfPlusDual;
  714. }
  715. else if(format == ChartImageFormat.EmfPlus)
  716. {
  717. emfType = EmfType.EmfPlusOnly;
  718. }
  719. this.chartPicture.SaveIntoMetafile(imageStream, emfType);
  720. }
  721. else
  722. {
  723. // Get chart image
  724. Image chartImage = this.chartPicture.GetImage();
  725. ImageFormat standardImageFormat = ImageFormat.Png;
  726. switch( format )
  727. {
  728. case ChartImageFormat.Bmp:
  729. standardImageFormat = ImageFormat.Bmp;
  730. break;
  731. case ChartImageFormat.Gif:
  732. standardImageFormat = ImageFormat.Gif;
  733. break;
  734. case ChartImageFormat.Jpeg:
  735. standardImageFormat = ImageFormat.Jpeg;
  736. break;
  737. case ChartImageFormat.Png:
  738. standardImageFormat = ImageFormat.Png;
  739. break;
  740. case ChartImageFormat.Tiff:
  741. standardImageFormat = ImageFormat.Tiff;
  742. break;
  743. }
  744. // Save image into the file
  745. chartImage.Save(imageStream, standardImageFormat);
  746. // Dispose image
  747. chartImage.Dispose();
  748. }
  749. // Reset flag
  750. this.chartPicture.isSavingAsImage = false;
  751. }
  752. #endregion
  753. #region Control public properties
  754. // Avalonia: this allows to draw chart on render thread.
  755. public new RightToLeft RightToLeft { get; set; } = RightToLeft.No;
  756. public event EventHandler OnModifing;
  757. public void CallOnModifing(object sender)
  758. {
  759. OnModifing?.Invoke(sender, null);
  760. }
  761. /// <summary>
  762. /// Array of custom palette colors.
  763. /// </summary>
  764. /// <remarks>
  765. /// When this custom colors array is non-empty the <b>Palette</b> property is ignored.
  766. /// </remarks>
  767. [
  768. SRCategory("CategoryAttributeAppearance"),
  769. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  770. SerializationVisibilityAttribute(SerializationVisibility.Attribute),
  771. SRDescription("DescriptionAttributeChart_PaletteCustomColors"),
  772. TypeConverter(typeof(ColorArrayConverter))
  773. ]
  774. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
  775. public Color[] PaletteCustomColors
  776. {
  777. set
  778. {
  779. this._dataManager.PaletteCustomColors = value;
  780. if(!this.disableInvalidates)
  781. {
  782. this.Invalidate();
  783. }
  784. }
  785. get
  786. {
  787. return this._dataManager.PaletteCustomColors;
  788. }
  789. }
  790. /// <summary>
  791. /// Method resets custom colors array. Internal use only.
  792. /// </summary>
  793. [EditorBrowsable(EditorBrowsableState.Never)]
  794. internal void ResetPaletteCustomColors()
  795. {
  796. this.PaletteCustomColors = new Color[0];
  797. }
  798. /// <summary>
  799. /// Method resets custom colors array. Internal use only.
  800. /// </summary>
  801. [EditorBrowsable(EditorBrowsableState.Never)]
  802. internal bool ShouldSerializePaletteCustomColors()
  803. {
  804. if(this.PaletteCustomColors == null ||
  805. this.PaletteCustomColors.Length == 0)
  806. {
  807. return false;
  808. }
  809. return true;
  810. }
  811. /// <summary>
  812. /// Indicates that non-critical chart exceptions will be suppressed.
  813. /// </summary>
  814. [
  815. SRCategory("CategoryAttributeMisc"),
  816. DefaultValue(false),
  817. SRDescription("DescriptionAttributeSuppressExceptions"),
  818. ]
  819. public bool SuppressExceptions
  820. {
  821. set
  822. {
  823. this.chartPicture.SuppressExceptions = value;
  824. }
  825. get
  826. {
  827. return this.chartPicture.SuppressExceptions;
  828. }
  829. }
  830. /// <summary>
  831. /// "The data source used to populate series data. Series ValueMember properties must be also set."
  832. /// </summary>
  833. [
  834. SRCategory("CategoryAttributeData"),
  835. Bindable(true),
  836. SRDescription("DescriptionAttributeDataSource"),
  837. DefaultValue(null),
  838. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  839. AttributeProvider(typeof(IListSource))
  840. ]
  841. public object DataSource
  842. {
  843. get
  844. {
  845. return chartPicture.DataSource;
  846. }
  847. set
  848. {
  849. chartPicture.DataSource = value;
  850. }
  851. }
  852. /// <summary>
  853. /// Chart named images collection.
  854. /// </summary>
  855. [
  856. SRCategory("CategoryAttributeChart"),
  857. Bindable(false),
  858. SRDescription("DescriptionAttributeChart_Images"),
  859. Browsable(false),
  860. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  861. ]
  862. public NamedImagesCollection Images
  863. {
  864. get
  865. {
  866. return _namedImages;
  867. }
  868. }
  869. /// <summary>
  870. /// Chart printing object.
  871. /// </summary>
  872. [
  873. SRCategory("CategoryAttributeChart"),
  874. Bindable(false),
  875. SRDescription("DescriptionAttributeChart_Printing"),
  876. Browsable(false),
  877. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  878. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  879. ]
  880. public PrintingManager Printing
  881. {
  882. get
  883. {
  884. return _printingManager;
  885. }
  886. }
  887. /// <summary>
  888. /// Chart series collection.
  889. /// </summary>
  890. [
  891. SRCategory("CategoryAttributeChart"),
  892. SRDescription("DescriptionAttributeChart_Series"),
  893. #if DESIGNER
  894. Editor(typeof(SeriesCollectionEditor), typeof(UITypeEditor)),
  895. #endif
  896. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  897. ]
  898. public SeriesCollection Series
  899. {
  900. get
  901. {
  902. return _dataManager.Series;
  903. }
  904. }
  905. /// <summary>
  906. /// Chart legend collection.
  907. /// </summary>
  908. [
  909. SRCategory("CategoryAttributeChart"),
  910. SRDescription("DescriptionAttributeLegends"),
  911. #if DESIGNER
  912. Editor(typeof(LegendCollectionEditor), typeof(UITypeEditor)),
  913. #endif
  914. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  915. ]
  916. public LegendCollection Legends
  917. {
  918. get
  919. {
  920. return chartPicture.Legends;
  921. }
  922. }
  923. /// <summary>
  924. /// Chart title collection.
  925. /// </summary>
  926. [
  927. SRCategory("CategoryAttributeChart"),
  928. SRDescription("DescriptionAttributeTitles"),
  929. #if DESIGNER
  930. Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor)),
  931. #endif
  932. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  933. ]
  934. public TitleCollection Titles
  935. {
  936. get
  937. {
  938. return chartPicture.Titles;
  939. }
  940. }
  941. /// <summary>
  942. /// Chart annotation collection.
  943. /// </summary>
  944. [
  945. SRCategory("CategoryAttributeChart"),
  946. SRDescription("DescriptionAttributeAnnotations3"),
  947. #if DESIGNER
  948. Editor(typeof(AnnotationCollectionEditor), typeof(UITypeEditor)),
  949. #endif
  950. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  951. ]
  952. public AnnotationCollection Annotations
  953. {
  954. get
  955. {
  956. return chartPicture.Annotations;
  957. }
  958. }
  959. /// <summary>
  960. /// BackImage is not used. Use BackImage property instead.
  961. /// </summary>
  962. [
  963. Browsable(false),
  964. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  965. EditorBrowsableAttribute(EditorBrowsableState.Never),
  966. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  967. ]
  968. public override Image BackgroundImage
  969. {
  970. get
  971. {
  972. return base.BackgroundImage;
  973. }
  974. set
  975. {
  976. base.BackgroundImage = value;
  977. }
  978. }
  979. /// <summary>
  980. /// Color palette to use
  981. /// </summary>
  982. [
  983. SRCategory("CategoryAttributeAppearance"),
  984. Bindable(true),
  985. SRDescription("DescriptionAttributePalette"),
  986. DefaultValue(ChartColorPalette.BrightPastel),
  987. #if DESIGNER
  988. Editor(typeof(ColorPaletteEditor), typeof(UITypeEditor))
  989. #endif
  990. ]
  991. public ChartColorPalette Palette
  992. {
  993. get
  994. {
  995. return _dataManager.Palette;
  996. }
  997. set
  998. {
  999. _dataManager.Palette = value;
  1000. this.dirtyFlag = true;
  1001. if(!this.disableInvalidates)
  1002. {
  1003. this.Invalidate();
  1004. }
  1005. }
  1006. }
  1007. /// <summary>
  1008. /// Specifies whether smoothing (antialiasing) is applied while drawing chart.
  1009. /// </summary>
  1010. [
  1011. SRCategory("CategoryAttributeImage"),
  1012. Bindable(true),
  1013. DefaultValue(typeof(AntiAliasingStyles), "All"),
  1014. SRDescription("DescriptionAttributeAntiAlias"),
  1015. #if DESIGNER
  1016. Editor(typeof(FlagsEnumUITypeEditor), typeof(UITypeEditor)),
  1017. #endif
  1018. ]
  1019. public FastReport.DataVisualization.Charting.AntiAliasingStyles AntiAliasing
  1020. {
  1021. get
  1022. {
  1023. return chartPicture.AntiAliasing;
  1024. }
  1025. set
  1026. {
  1027. if(chartPicture.AntiAliasing != value)
  1028. {
  1029. chartPicture.AntiAliasing = value;
  1030. this.dirtyFlag = true;
  1031. if(!this.disableInvalidates)
  1032. {
  1033. this.Invalidate();
  1034. }
  1035. }
  1036. }
  1037. }
  1038. /// <summary>
  1039. /// Specifies the quality of text antialiasing.
  1040. /// </summary>
  1041. [
  1042. SRCategory("CategoryAttributeImage"),
  1043. Bindable(true),
  1044. DefaultValue(typeof(TextAntiAliasingQuality), "High"),
  1045. SRDescription("DescriptionAttributeTextAntiAliasingQuality")
  1046. ]
  1047. public TextAntiAliasingQuality TextAntiAliasingQuality
  1048. {
  1049. get
  1050. {
  1051. return chartPicture.TextAntiAliasingQuality;
  1052. }
  1053. set
  1054. {
  1055. chartPicture.TextAntiAliasingQuality = value;
  1056. this.dirtyFlag = true;
  1057. if(!this.disableInvalidates)
  1058. {
  1059. this.Invalidate();
  1060. }
  1061. }
  1062. }
  1063. /// <summary>
  1064. /// Specifies whether smoothing is applied while drawing shadows.
  1065. /// </summary>
  1066. [
  1067. SRCategory("CategoryAttributeImage"),
  1068. Bindable(true),
  1069. DefaultValue(true),
  1070. SRDescription("DescriptionAttributeChart_SoftShadows"),
  1071. ]
  1072. public bool IsSoftShadows
  1073. {
  1074. get
  1075. {
  1076. return chartPicture.IsSoftShadows;
  1077. }
  1078. set
  1079. {
  1080. chartPicture.IsSoftShadows = value;
  1081. this.dirtyFlag = true;
  1082. if(!this.disableInvalidates)
  1083. {
  1084. this.Invalidate();
  1085. }
  1086. }
  1087. }
  1088. /// <summary>
  1089. /// Reference to chart area collection
  1090. /// </summary>
  1091. [
  1092. SRCategory("CategoryAttributeChart"),
  1093. Bindable(true),
  1094. SRDescription("DescriptionAttributeChartAreas"),
  1095. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  1096. #if DESIGNER
  1097. Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor)),
  1098. #endif
  1099. ]
  1100. public ChartAreaCollection ChartAreas
  1101. {
  1102. get
  1103. {
  1104. return chartPicture.ChartAreas;
  1105. }
  1106. }
  1107. /// <summary>
  1108. /// Back ground color for the Chart
  1109. /// </summary>
  1110. [
  1111. SRCategory("CategoryAttributeAppearance"),
  1112. Bindable(true),
  1113. DefaultValue(typeof(Color), "White"),
  1114. SRDescription("DescriptionAttributeBackColor"),
  1115. TypeConverter(typeof(ColorConverter)),
  1116. #if DESIGNER
  1117. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  1118. #endif
  1119. ]
  1120. public new Color BackColor
  1121. {
  1122. get
  1123. {
  1124. return chartPicture.BackColor;
  1125. }
  1126. set
  1127. {
  1128. if (chartPicture.BackColor != value)
  1129. {
  1130. chartPicture.BackColor = value;
  1131. this.dirtyFlag = true;
  1132. if (!this.disableInvalidates)
  1133. {
  1134. this.Invalidate();
  1135. }
  1136. // Call notification event
  1137. this.OnBackColorChanged(EventArgs.Empty);
  1138. }
  1139. }
  1140. }
  1141. /// <summary>
  1142. /// Fore color propery (not used)
  1143. /// </summary>
  1144. [
  1145. SRCategory("CategoryAttributeAppearance"),
  1146. Bindable(false),
  1147. Browsable(false),
  1148. DefaultValue(typeof(Color), ""),
  1149. SRDescription("DescriptionAttributeForeColor"),
  1150. TypeConverter(typeof(ColorConverter)),
  1151. #if DESIGNER
  1152. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  1153. #endif
  1154. ]
  1155. public new Color ForeColor
  1156. {
  1157. get
  1158. {
  1159. return Color.Empty;
  1160. }
  1161. set
  1162. {
  1163. }
  1164. }
  1165. /// <summary>
  1166. /// Fore color propery (not used)
  1167. /// </summary>
  1168. [
  1169. SRCategory("CategoryAttributeLayout"),
  1170. Bindable(true),
  1171. DefaultValue(typeof(System.Drawing.Size), "300, 300"),
  1172. SRDescription("DescriptionAttributeChart_Size"),
  1173. ]
  1174. public new System.Drawing.Size Size
  1175. {
  1176. get
  1177. {
  1178. return base.Size;
  1179. }
  1180. set
  1181. {
  1182. chartPicture.InspectChartDimensions(value.Width, value.Height);
  1183. base.Size = value;
  1184. }
  1185. }
  1186. /// <summary>
  1187. /// Series data manipulator
  1188. /// </summary>
  1189. [
  1190. SRCategory("CategoryAttributeData"),
  1191. SRDescription("DescriptionAttributeDataManipulator"),
  1192. Browsable(false),
  1193. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  1194. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1195. ]
  1196. public DataManipulator DataManipulator
  1197. {
  1198. get
  1199. {
  1200. return chartPicture.DataManipulator;
  1201. }
  1202. }
  1203. /// <summary>
  1204. /// Chart serializer object.
  1205. /// </summary>
  1206. [
  1207. SRCategory("CategoryAttributeSerializer"),
  1208. SRDescription("DescriptionAttributeChart_Serializer"),
  1209. Browsable(false),
  1210. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  1211. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1212. ]
  1213. public ChartSerializer Serializer
  1214. {
  1215. get
  1216. {
  1217. return _chartSerializer;
  1218. }
  1219. }
  1220. /// <summary>
  1221. /// Title font
  1222. /// </summary>
  1223. [
  1224. SRCategory("CategoryAttributeCharttitle"),
  1225. Bindable(false),
  1226. Browsable(false),
  1227. EditorBrowsableAttribute(EditorBrowsableState.Never),
  1228. DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt"),
  1229. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  1230. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1231. ]
  1232. public new Font Font
  1233. {
  1234. get
  1235. {
  1236. return base.Font;
  1237. }
  1238. set
  1239. {
  1240. base.Font = value;
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// Back Hatch style
  1245. /// </summary>
  1246. [
  1247. SRCategory("CategoryAttributeAppearance"),
  1248. Bindable(true),
  1249. DefaultValue(ChartHatchStyle.None),
  1250. SRDescription("DescriptionAttributeBackHatchStyle"),
  1251. #if DESIGNER
  1252. Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))
  1253. #endif
  1254. ]
  1255. public ChartHatchStyle BackHatchStyle
  1256. {
  1257. get
  1258. {
  1259. return chartPicture.BackHatchStyle;
  1260. }
  1261. set
  1262. {
  1263. chartPicture.BackHatchStyle = value;
  1264. this.dirtyFlag = true;
  1265. if(!this.disableInvalidates)
  1266. {
  1267. this.Invalidate();
  1268. }
  1269. }
  1270. }
  1271. /// <summary>
  1272. /// Chart area background image
  1273. /// </summary>
  1274. [
  1275. SRCategory("CategoryAttributeAppearance"),
  1276. Bindable(true),
  1277. DefaultValue(""),
  1278. SRDescription("DescriptionAttributeBackImage"),
  1279. NotifyParentPropertyAttribute(true),
  1280. #if DESIGNER
  1281. Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
  1282. #endif
  1283. ]
  1284. public string BackImage
  1285. {
  1286. get
  1287. {
  1288. return chartPicture.BackImage;
  1289. }
  1290. set
  1291. {
  1292. chartPicture.BackImage = value;
  1293. this.dirtyFlag = true;
  1294. if(!this.disableInvalidates)
  1295. {
  1296. this.Invalidate();
  1297. }
  1298. }
  1299. }
  1300. /// <summary>
  1301. /// Chart area background image drawing mode.
  1302. /// </summary>
  1303. [
  1304. SRCategory("CategoryAttributeAppearance"),
  1305. Bindable(true),
  1306. DefaultValue(ChartImageWrapMode.Tile),
  1307. NotifyParentPropertyAttribute(true),
  1308. SRDescription("DescriptionAttributeImageWrapMode"),
  1309. ]
  1310. public ChartImageWrapMode BackImageWrapMode
  1311. {
  1312. get
  1313. {
  1314. return chartPicture.BackImageWrapMode;
  1315. }
  1316. set
  1317. {
  1318. chartPicture.BackImageWrapMode = value;
  1319. this.dirtyFlag = true;
  1320. if(!this.disableInvalidates)
  1321. {
  1322. this.Invalidate();
  1323. }
  1324. }
  1325. }
  1326. /// <summary>
  1327. /// Background image transparent color.
  1328. /// </summary>
  1329. [
  1330. SRCategory("CategoryAttributeAppearance"),
  1331. Bindable(true),
  1332. DefaultValue(typeof(Color), ""),
  1333. NotifyParentPropertyAttribute(true),
  1334. SRDescription("DescriptionAttributeImageTransparentColor"),
  1335. TypeConverter(typeof(ColorConverter)),
  1336. #if DESIGNER
  1337. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  1338. #endif
  1339. ]
  1340. public Color BackImageTransparentColor
  1341. {
  1342. get
  1343. {
  1344. return chartPicture.BackImageTransparentColor;
  1345. }
  1346. set
  1347. {
  1348. chartPicture.BackImageTransparentColor = value;
  1349. this.dirtyFlag = true;
  1350. if(!this.disableInvalidates)
  1351. {
  1352. this.Invalidate();
  1353. }
  1354. }
  1355. }
  1356. /// <summary>
  1357. /// Background image alignment used by ClampUnscale drawing mode.
  1358. /// </summary>
  1359. [
  1360. SRCategory("CategoryAttributeAppearance"),
  1361. Bindable(true),
  1362. DefaultValue(ChartImageAlignmentStyle.TopLeft),
  1363. NotifyParentPropertyAttribute(true),
  1364. SRDescription("DescriptionAttributeBackImageAlign"),
  1365. ]
  1366. public ChartImageAlignmentStyle BackImageAlignment
  1367. {
  1368. get
  1369. {
  1370. return chartPicture.BackImageAlignment;
  1371. }
  1372. set
  1373. {
  1374. chartPicture.BackImageAlignment = value;
  1375. this.dirtyFlag = true;
  1376. if(!this.disableInvalidates)
  1377. {
  1378. this.Invalidate();
  1379. }
  1380. }
  1381. }
  1382. /// <summary>
  1383. /// A type for the background gradient
  1384. /// </summary>
  1385. [
  1386. SRCategory("CategoryAttributeAppearance"),
  1387. Bindable(true),
  1388. DefaultValue(GradientStyle.None),
  1389. SRDescription("DescriptionAttributeBackGradientStyle"),
  1390. #if DESIGNER
  1391. Editor(typeof(GradientEditor), typeof(UITypeEditor))
  1392. #endif
  1393. ]
  1394. public GradientStyle BackGradientStyle
  1395. {
  1396. get
  1397. {
  1398. return chartPicture.BackGradientStyle;
  1399. }
  1400. set
  1401. {
  1402. chartPicture.BackGradientStyle = value;
  1403. this.dirtyFlag = true;
  1404. if(!this.disableInvalidates)
  1405. {
  1406. this.Invalidate();
  1407. }
  1408. }
  1409. }
  1410. /// <summary>
  1411. /// The second color which is used for a gradient
  1412. /// </summary>
  1413. [
  1414. SRCategory("CategoryAttributeAppearance"),
  1415. Bindable(true),
  1416. DefaultValue(typeof(Color), ""),
  1417. SRDescription("DescriptionAttributeBackSecondaryColor"),
  1418. TypeConverter(typeof(ColorConverter)),
  1419. #if DESIGNER
  1420. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  1421. #endif
  1422. ]
  1423. public Color BackSecondaryColor
  1424. {
  1425. get
  1426. {
  1427. return chartPicture.BackSecondaryColor;
  1428. }
  1429. set
  1430. {
  1431. chartPicture.BackSecondaryColor = value;
  1432. this.dirtyFlag = true;
  1433. if(!this.disableInvalidates)
  1434. {
  1435. this.Invalidate();
  1436. }
  1437. }
  1438. }
  1439. /// <summary>
  1440. /// Border color for the Chart
  1441. /// </summary>
  1442. [
  1443. SRCategory("CategoryAttributeAppearance"),
  1444. Bindable(false),
  1445. Browsable(false),
  1446. EditorBrowsable(EditorBrowsableState.Never),
  1447. DefaultValue(typeof(Color), "White"),
  1448. SRDescription("DescriptionAttributeBorderColor"),
  1449. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  1450. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  1451. TypeConverter(typeof(ColorConverter)),
  1452. #if DESIGNER
  1453. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  1454. #endif
  1455. ]
  1456. public Color BorderColor
  1457. {
  1458. get
  1459. {
  1460. return chartPicture.BorderColor;
  1461. }
  1462. set
  1463. {
  1464. chartPicture.BorderColor = value;
  1465. this.dirtyFlag = true;
  1466. if(!this.disableInvalidates)
  1467. {
  1468. this.Invalidate();
  1469. }
  1470. }
  1471. }
  1472. /// <summary>
  1473. /// The width of the border line
  1474. /// </summary>
  1475. [
  1476. SRCategory("CategoryAttributeAppearance"),
  1477. Bindable(false),
  1478. Browsable(false),
  1479. EditorBrowsable(EditorBrowsableState.Never),
  1480. DefaultValue(1),
  1481. SRDescription("DescriptionAttributeChart_BorderlineWidth"),
  1482. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  1483. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1484. ]
  1485. public int BorderWidth
  1486. {
  1487. get
  1488. {
  1489. return chartPicture.BorderWidth;
  1490. }
  1491. set
  1492. {
  1493. chartPicture.BorderWidth = value;
  1494. this.dirtyFlag = true;
  1495. if(!this.disableInvalidates)
  1496. {
  1497. this.Invalidate();
  1498. }
  1499. }
  1500. }
  1501. /// <summary>
  1502. /// The style of the border line
  1503. /// </summary>
  1504. [
  1505. SRCategory("CategoryAttributeAppearance"),
  1506. Bindable(false),
  1507. Browsable(false),
  1508. EditorBrowsable(EditorBrowsableState.Never),
  1509. DefaultValue(ChartDashStyle.NotSet),
  1510. SRDescription("DescriptionAttributeBorderDashStyle"),
  1511. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  1512. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1513. ]
  1514. public ChartDashStyle BorderDashStyle
  1515. {
  1516. get
  1517. {
  1518. return chartPicture.BorderDashStyle;
  1519. }
  1520. set
  1521. {
  1522. chartPicture.BorderDashStyle = value;
  1523. this.dirtyFlag = true;
  1524. if(!this.disableInvalidates)
  1525. {
  1526. this.Invalidate();
  1527. }
  1528. }
  1529. }
  1530. /// <summary>
  1531. /// Border color for the Chart
  1532. /// </summary>
  1533. [
  1534. SRCategory("CategoryAttributeAppearance"),
  1535. Bindable(true),
  1536. DefaultValue(typeof(Color), "White"),
  1537. SRDescription("DescriptionAttributeBorderColor"),
  1538. TypeConverter(typeof(ColorConverter)),
  1539. #if DESIGNER
  1540. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  1541. #endif
  1542. ]
  1543. public Color BorderlineColor
  1544. {
  1545. get
  1546. {
  1547. return chartPicture.BorderColor;
  1548. }
  1549. set
  1550. {
  1551. chartPicture.BorderColor = value;
  1552. this.dirtyFlag = true;
  1553. if(!this.disableInvalidates)
  1554. {
  1555. this.Invalidate();
  1556. }
  1557. }
  1558. }
  1559. /// <summary>
  1560. /// The width of the border line
  1561. /// </summary>
  1562. [
  1563. SRCategory("CategoryAttributeAppearance"),
  1564. Bindable(true),
  1565. DefaultValue(1),
  1566. SRDescription("DescriptionAttributeChart_BorderlineWidth"),
  1567. ]
  1568. public int BorderlineWidth
  1569. {
  1570. get
  1571. {
  1572. return chartPicture.BorderWidth;
  1573. }
  1574. set
  1575. {
  1576. chartPicture.BorderWidth = value;
  1577. this.dirtyFlag = true;
  1578. if(!this.disableInvalidates)
  1579. {
  1580. this.Invalidate();
  1581. }
  1582. }
  1583. }
  1584. /// <summary>
  1585. /// The style of the border line
  1586. /// </summary>
  1587. [
  1588. SRCategory("CategoryAttributeAppearance"),
  1589. Bindable(true),
  1590. DefaultValue(ChartDashStyle.NotSet),
  1591. SRDescription("DescriptionAttributeBorderDashStyle"),
  1592. ]
  1593. public ChartDashStyle BorderlineDashStyle
  1594. {
  1595. get
  1596. {
  1597. return chartPicture.BorderDashStyle;
  1598. }
  1599. set
  1600. {
  1601. chartPicture.BorderDashStyle = value;
  1602. this.dirtyFlag = true;
  1603. if(!this.disableInvalidates)
  1604. {
  1605. this.Invalidate();
  1606. }
  1607. }
  1608. }
  1609. /// <summary>
  1610. /// Chart border skin style.
  1611. /// </summary>
  1612. [
  1613. SRCategory("CategoryAttributeAppearance"),
  1614. Bindable(true),
  1615. DefaultValue(BorderSkinStyle.None),
  1616. SRDescription("DescriptionAttributeBorderSkin"),
  1617. NotifyParentPropertyAttribute(true),
  1618. TypeConverterAttribute(typeof(LegendConverter)),
  1619. DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
  1620. ]
  1621. public BorderSkin BorderSkin
  1622. {
  1623. get
  1624. {
  1625. return chartPicture.BorderSkin;
  1626. }
  1627. set
  1628. {
  1629. chartPicture.BorderSkin = value;
  1630. this.dirtyFlag = true;
  1631. if(!this.disableInvalidates)
  1632. {
  1633. this.Invalidate();
  1634. }
  1635. }
  1636. }
  1637. /// <summary>
  1638. /// Build number of the control
  1639. /// </summary>
  1640. [
  1641. SRDescription("DescriptionAttributeChart_BuildNumber"),
  1642. Browsable(false),
  1643. EditorBrowsable(EditorBrowsableState.Never),
  1644. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  1645. DefaultValue("")
  1646. ]
  1647. public string BuildNumber
  1648. {
  1649. get
  1650. {
  1651. // Get build number from the assembly
  1652. string buildNumber = String.Empty;
  1653. Assembly assembly = Assembly.GetExecutingAssembly();
  1654. if(assembly != null)
  1655. {
  1656. buildNumber = assembly.FullName.ToUpper(CultureInfo.InvariantCulture);
  1657. int versionIndex = buildNumber.IndexOf("VERSION=", StringComparison.Ordinal);
  1658. if(versionIndex >= 0)
  1659. {
  1660. buildNumber = buildNumber.Substring(versionIndex + 8);
  1661. }
  1662. versionIndex = buildNumber.IndexOf(",", StringComparison.Ordinal);
  1663. if(versionIndex >= 0)
  1664. {
  1665. buildNumber = buildNumber.Substring(0, versionIndex);
  1666. }
  1667. }
  1668. return buildNumber;
  1669. }
  1670. }
  1671. /// <summary>
  1672. /// Vertical resolution of the chart renderer.
  1673. /// </summary>
  1674. /// <remarks>
  1675. /// This property is for the internal use only.
  1676. /// </remarks>
  1677. [
  1678. Browsable(false),
  1679. EditorBrowsable(EditorBrowsableState.Never),
  1680. SRCategory("CategoryAttributeMisc"),
  1681. DefaultValue(96.0),
  1682. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  1683. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1684. ]
  1685. public double RenderingDpiY
  1686. {
  1687. set
  1688. {
  1689. Chart.renderingDpiY = value;
  1690. }
  1691. get
  1692. {
  1693. return Chart.renderingDpiY;
  1694. }
  1695. }
  1696. /// <summary>
  1697. /// Horizontal resolution of the chart renderer.
  1698. /// </summary>
  1699. /// <remarks>
  1700. /// This property is for the internal use only.
  1701. /// </remarks>
  1702. [
  1703. Browsable(false),
  1704. EditorBrowsable(EditorBrowsableState.Never),
  1705. SRCategory("CategoryAttributeMisc"),
  1706. DefaultValue(96.0),
  1707. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  1708. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  1709. ]
  1710. public double RenderingDpiX
  1711. {
  1712. set
  1713. {
  1714. Chart.renderingDpiX = value;
  1715. }
  1716. get
  1717. {
  1718. return Chart.renderingDpiX;
  1719. }
  1720. }
  1721. #endregion
  1722. #region Control public methods
  1723. /// <summary>
  1724. /// Loads chart appearance template from file.
  1725. /// </summary>
  1726. /// <param name="name">Template file name to load from.</param>
  1727. public void LoadTemplate(string name)
  1728. {
  1729. chartPicture.LoadTemplate(name);
  1730. }
  1731. /// <summary>
  1732. /// Loads chart appearance template from stream.
  1733. /// </summary>
  1734. /// <param name="stream">Template stream to load from.</param>
  1735. public void LoadTemplate(Stream stream)
  1736. {
  1737. chartPicture.LoadTemplate(stream);
  1738. }
  1739. /// <summary>
  1740. /// Applies palette colors to series or data points.
  1741. /// </summary>
  1742. public void ApplyPaletteColors()
  1743. {
  1744. // Apply palette colors to series
  1745. this._dataManager.ApplyPaletteColors();
  1746. // Apply palette colors to data Points in series
  1747. foreach(Series series in this.Series)
  1748. {
  1749. // Check if palette colors should be aplied to the points
  1750. bool applyToPoints = false;
  1751. if(series.Palette != ChartColorPalette.None)
  1752. {
  1753. applyToPoints = true;
  1754. }
  1755. else
  1756. {
  1757. IChartType chartType = this._chartTypeRegistry.GetChartType(series.ChartType);
  1758. applyToPoints = chartType.ApplyPaletteColorsToPoints;
  1759. }
  1760. // Apply palette colors to the points
  1761. if(applyToPoints)
  1762. {
  1763. series.ApplyPaletteColors();
  1764. }
  1765. }
  1766. }
  1767. /// <summary>
  1768. /// Checks if control is in design mode.
  1769. /// </summary>
  1770. /// <returns>True if control is in design mode.</returns>
  1771. internal bool IsDesignMode()
  1772. {
  1773. return this.DesignMode;
  1774. }
  1775. /// <summary>
  1776. /// Reset auto calculated chart properties values to "Auto".
  1777. /// </summary>
  1778. public void ResetAutoValues()
  1779. {
  1780. // Reset auto calculated series properties values
  1781. foreach(Series series in this.Series)
  1782. {
  1783. series.ResetAutoValues();
  1784. }
  1785. // Reset auto calculated axis properties values
  1786. foreach(ChartArea chartArea in this.ChartAreas)
  1787. {
  1788. chartArea.ResetAutoValues();
  1789. }
  1790. }
  1791. /// <summary>
  1792. /// This method performs the hit test and returns a HitTestResult objects.
  1793. /// </summary>
  1794. /// <param name="x">X coordinate</param>
  1795. /// <param name="y">Y coordinate</param>
  1796. /// <returns>Hit test result object</returns>
  1797. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1798. Justification = "X and Y are cartesian coordinates and well understood")]
  1799. public HitTestResult HitTest( int x, int y )
  1800. {
  1801. return selection.HitTest( x, y );
  1802. }
  1803. /// <summary>
  1804. /// This method performs the hit test and returns a HitTestResult object.
  1805. /// </summary>
  1806. /// <param name="x">X coordinate</param>
  1807. /// <param name="y">Y coordinate</param>
  1808. /// <param name="ignoreTransparent">Indicates that transparent elements should be ignored.</param>
  1809. /// <returns>Hit test result object</returns>
  1810. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1811. Justification = "X and Y are cartesian coordinates and well understood")]
  1812. public HitTestResult HitTest( int x, int y, bool ignoreTransparent )
  1813. {
  1814. return selection.HitTest( x, y, ignoreTransparent );
  1815. }
  1816. /// <summary>
  1817. /// This method performs the hit test and returns a HitTestResult object.
  1818. /// </summary>
  1819. /// <param name="x">X coordinate</param>
  1820. /// <param name="y">Y coordinate</param>
  1821. /// <param name="requestedElement">Only this chart element will be hit tested.</param>
  1822. /// <returns>Hit test result object</returns>
  1823. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1824. Justification = "X and Y are cartesian coordinates and well understood")]
  1825. public HitTestResult HitTest( int x, int y, ChartElementType requestedElement )
  1826. {
  1827. return selection.HitTest( x, y, requestedElement);
  1828. }
  1829. /// <summary>
  1830. /// Call this method to determine the chart element,
  1831. /// if any, that is located at a point defined by the given X and Y
  1832. /// coordinates.
  1833. /// <seealso cref="HitTestResult"/></summary>
  1834. /// <param name="x">The X coordinate for the point in question.
  1835. /// Often obtained from a parameter in an event
  1836. /// (e.g. the X parameter value in the MouseDown event).</param>
  1837. /// <param name="y">The Y coordinate for the point in question.
  1838. /// Often obtained from a parameter in an event
  1839. /// (e.g. the Y parameter value in the MouseDown event).</param>
  1840. /// <param name="ignoreTransparent">Indicates that transparent
  1841. /// elements should be ignored.</param>
  1842. /// <param name="requestedElement">
  1843. /// An array of type which specify the types
  1844. /// to test for, on order to filter the result. If omitted checking for
  1845. /// elementTypes will be ignored and all kind of elementTypes will be
  1846. /// valid.
  1847. /// </param>
  1848. /// <returns>
  1849. /// A array of <see cref="HitTestResult"/> objects,
  1850. /// which provides information concerning the chart element
  1851. /// (if any) that is at the specified location. Result contains at least
  1852. /// one element, which could be ChartElementType.Nothing.
  1853. /// The objects in the result are sorted in from top to bottom of
  1854. /// different layers of control. </returns>
  1855. /// <remarks>Call this method to determine the gauge element
  1856. /// (if any) that is located at a specified point. Often this method is used in
  1857. /// some mouse-related event (e.g. MouseDown)
  1858. /// to determine what gauge element the end-user clicked on.
  1859. /// The X and Y mouse coordinates obtained from the
  1860. /// event parameters are then used for the X and Y parameter
  1861. /// values of this method call. The returned
  1862. /// <see cref="HitTestResult"/> object's properties
  1863. /// can then be used to determine what chart element was clicked on,
  1864. /// and also provides a reference to the actual object selected (if
  1865. /// any).</remarks>
  1866. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1867. Justification = "X and Y are cartesian coordinates and well understood")]
  1868. public HitTestResult[] HitTest(int x, int y, bool ignoreTransparent, params ChartElementType[] requestedElement)
  1869. {
  1870. return this.selection.HitTest(x, y, ignoreTransparent, requestedElement);
  1871. }
  1872. /// <summary>
  1873. /// Gets the chart element outline.
  1874. /// </summary>
  1875. /// <param name="element">The chart object.</param>
  1876. /// <param name="elementType">Type of the element.</param>
  1877. /// <returns> A <see cref="ChartElementOutline"/> object which contains
  1878. /// 1) An array of points in absolute coordinates which can be used as outline markers arround this chart element.
  1879. /// 2) A GraphicsPath for drawing aouline around this chart emenent.
  1880. /// </returns>
  1881. /// <remarks>
  1882. /// If the <paramref name="element"/> is not part of the chart or <paramref name="elementType"/> cannot be combined
  1883. /// with <paramref name="element"/> then the result will contain empty array of marker points.
  1884. /// The marker points are sorted clockwize.
  1885. /// </remarks>
  1886. public ChartElementOutline GetChartElementOutline(object element, ChartElementType elementType)
  1887. {
  1888. return this.selection.GetChartElementOutline(element, elementType);
  1889. }
  1890. #endregion
  1891. #region Control protected methods
  1892. protected override void OnGotFocus(EventArgs e)
  1893. {
  1894. base.OnGotFocus(e);
  1895. using (Graphics g = Graphics.FromHwndInternal(Handle))
  1896. {
  1897. ControlPaint.DrawFocusRectangle(g, new Rectangle(1, 1, Size.Width - 2, Size.Height - 2));
  1898. }
  1899. }
  1900. protected override void OnLostFocus(EventArgs e)
  1901. {
  1902. base.OnLostFocus(e);
  1903. using (Graphics g = Graphics.FromHwndInternal(Handle))
  1904. {
  1905. using (Brush b = new SolidBrush(BackColor))
  1906. {
  1907. Rectangle topBorder = new Rectangle(1, 1, Size.Width - 2, 1);
  1908. g.FillRectangle(b, topBorder);
  1909. Rectangle rightBorder = new Rectangle(Size.Width - 2, 1, 1, Size.Height - 2);
  1910. g.FillRectangle(b, rightBorder);
  1911. Rectangle bottomBorder = new Rectangle(1, Size.Height - 2, Size.Width - 2, 1);
  1912. g.FillRectangle(b, bottomBorder);
  1913. Rectangle leftBorder = new Rectangle(1, 1, 1, Size.Height - 2);
  1914. g.FillRectangle(b, leftBorder);
  1915. }
  1916. }
  1917. }
  1918. #endregion
  1919. #region ISupportInitialize implementation
  1920. /// <summary>
  1921. /// Signals the object that initialization is starting.
  1922. /// </summary>
  1923. public void BeginInit()
  1924. {
  1925. // Disable control invalidation
  1926. disableInvalidates = true;
  1927. }
  1928. /// <summary>
  1929. /// Signals the object that initialization is complete.
  1930. /// </summary>
  1931. public void EndInit()
  1932. {
  1933. // Enable control invalidation
  1934. disableInvalidates = false;
  1935. // If control is durty - invalidate it
  1936. if(this.dirtyFlag)
  1937. {
  1938. base.Invalidate();
  1939. }
  1940. }
  1941. #endregion
  1942. #region Control mouse events
  1943. /// <summary>
  1944. /// Raises the <see cref="E:System.Windows.Forms.Control.CursorChanged"/> event.
  1945. /// </summary>
  1946. /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
  1947. protected override void OnCursorChanged(EventArgs e)
  1948. {
  1949. this.defaultCursor = this.Cursor;
  1950. base.OnCursorChanged(e);
  1951. }
  1952. /// <summary>
  1953. /// Mouse button pressed in the control.
  1954. /// </summary>
  1955. /// <param name="e">Event arguments.</param>
  1956. protected override void OnMouseDown(MouseEventArgs e)
  1957. {
  1958. OnChartMouseDown(e);
  1959. }
  1960. /// <summary>
  1961. /// Mouse button pressed in the control.
  1962. /// </summary>
  1963. /// <param name="e">Event arguments.</param>
  1964. internal void OnChartMouseDown(MouseEventArgs e)
  1965. {
  1966. bool handled = false;
  1967. if(!handled)
  1968. {
  1969. // Notify annotation object collection about the mouse down event
  1970. this.Annotations.OnMouseDown(e, ref handled);
  1971. }
  1972. // Loop through all areas and notify required object about the event
  1973. if(!handled)
  1974. {
  1975. foreach(ChartArea area in this.ChartAreas)
  1976. {
  1977. // No cursor or scroll bar support in 3D
  1978. if(!area.Area3DStyle.Enable3D &&
  1979. !area.chartAreaIsCurcular
  1980. && area.Visible)
  1981. {
  1982. foreach(Axis axis in area.Axes)
  1983. {
  1984. // Notify axis scroll bar
  1985. axis.ScrollBar.ScrollBar_MouseDown(this, e);
  1986. }
  1987. // Notify area X and Y cursors
  1988. area.CursorX.Cursor_MouseDown(this, e);
  1989. area.CursorY.Cursor_MouseDown(this, e);
  1990. }
  1991. }
  1992. }
  1993. // Call the base class
  1994. base.OnMouseDown(e);
  1995. }
  1996. /// <summary>
  1997. /// Mouse button up in the control.
  1998. /// </summary>
  1999. /// <param name="e">Event arguments.</param>
  2000. protected override void OnMouseUp(MouseEventArgs e)
  2001. {
  2002. OnChartMouseUp(e);
  2003. }
  2004. /// <summary>
  2005. /// Mouse button up in the control.
  2006. /// </summary>
  2007. /// <param name="e">Event arguments.</param>
  2008. internal void OnChartMouseUp(MouseEventArgs e)
  2009. {
  2010. // Loop through all areas and notify required object about the event
  2011. foreach(ChartArea area in this.ChartAreas)
  2012. {
  2013. // No cursor or scroll bar support in 3D
  2014. if(!area.Area3DStyle.Enable3D &&
  2015. !area.chartAreaIsCurcular
  2016. && area.Visible)
  2017. {
  2018. foreach(Axis axis in area.Axes)
  2019. {
  2020. // Notify axis scroll bar
  2021. axis.ScrollBar.ScrollBar_MouseUp(this, e);
  2022. }
  2023. // Notify area X and Y cursors
  2024. area.CursorX.Cursor_MouseUp(this, e);
  2025. area.CursorY.Cursor_MouseUp(this, e);
  2026. }
  2027. }
  2028. // Notify annotation object collection about the mouse down event
  2029. this.Annotations.OnMouseUp(e);
  2030. // Call the base class
  2031. base.OnMouseUp(e);
  2032. }
  2033. /// <summary>
  2034. /// Mouse moved in the control.
  2035. /// </summary>
  2036. /// <param name="e">Event arguments.</param>
  2037. protected override void OnMouseMove(MouseEventArgs e)
  2038. {
  2039. OnChartMouseMove(e);
  2040. }
  2041. /// <summary>
  2042. /// Mouse moved in the control.
  2043. /// </summary>
  2044. /// <param name="e">Event arguments.</param>
  2045. internal void OnChartMouseMove(MouseEventArgs e)
  2046. {
  2047. // Flag which indicates if event was already isHandled
  2048. bool handled = false;
  2049. // Loop through all areas and notify required object about the event
  2050. foreach(ChartArea area in this.ChartAreas)
  2051. {
  2052. // No cursor or scroll bar support in 3D
  2053. if(!area.Area3DStyle.Enable3D &&
  2054. !area.chartAreaIsCurcular
  2055. && area.Visible)
  2056. {
  2057. foreach(Axis axis in area.Axes)
  2058. {
  2059. // Notify axis scroll bar
  2060. axis.ScrollBar.ScrollBar_MouseMove(e, ref handled);
  2061. }
  2062. // Notify area X and Y cursors
  2063. area.CursorX.Cursor_MouseMove(e, ref handled);
  2064. area.CursorY.Cursor_MouseMove(e, ref handled);
  2065. }
  2066. }
  2067. // Notify Selection object for tool tips processing
  2068. if(!handled)
  2069. {
  2070. this.selection.Selection_MouseMove(this, e);
  2071. }
  2072. // Notify annotation object collection about the mouse down event
  2073. if(!handled)
  2074. {
  2075. this.Annotations.OnMouseMove(e);
  2076. }
  2077. // Call the base class
  2078. base.OnMouseMove(e);
  2079. }
  2080. /// <summary>
  2081. /// Mouse was double clicked on the control.
  2082. /// </summary>
  2083. /// <param name="e">Event arguments</param>
  2084. protected override void OnDoubleClick(EventArgs e)
  2085. {
  2086. // Notify annotation object collection about the mouse down event
  2087. this.Annotations.OnDoubleClick();
  2088. // Call the base class
  2089. base.OnDoubleClick(e);
  2090. }
  2091. #endregion
  2092. #region Chart get tool tip text events
  2093. /// <summary>
  2094. /// Called before showing the tooltip to get the tooltip text.
  2095. /// </summary>
  2096. [SRDescription("DescriptionAttributeChartEvent_GetToolTipText"),
  2097. SRCategory("CategoryAttributeToolTips")]
  2098. public event EventHandler<ToolTipEventArgs> GetToolTipText;
  2099. /// <summary>
  2100. /// Checks if GetToolTipEvent is used
  2101. /// </summary>
  2102. /// <returns>True if event is used</returns>
  2103. internal bool IsToolTipEventUsed()
  2104. {
  2105. if(GetToolTipText != null)
  2106. {
  2107. return true;
  2108. }
  2109. return false;
  2110. }
  2111. /// <summary>
  2112. /// Calls event delegate.
  2113. /// </summary>
  2114. /// <param name="arguments">Cursor event arguments.</param>
  2115. internal void OnGetToolTipText(ToolTipEventArgs arguments)
  2116. {
  2117. if(GetToolTipText != null)
  2118. {
  2119. GetToolTipText(this, arguments);
  2120. }
  2121. }
  2122. #endregion
  2123. #region Chart area cursor and selection events
  2124. /// <summary>
  2125. /// Called when cursor position is about to change.
  2126. /// </summary>
  2127. [SRDescription("DescriptionAttributeChartEvent_CursorPositionChanging"),
  2128. SRCategory("CategoryAttributeCursor")]
  2129. public event EventHandler<CursorEventArgs> CursorPositionChanging;
  2130. /// <summary>
  2131. /// Called when cursor position is changed.
  2132. /// </summary>
  2133. [SRDescription("DescriptionAttributeChartEvent_CursorPositionChanged"),
  2134. SRCategory("CategoryAttributeCursor")]
  2135. public event EventHandler<CursorEventArgs> CursorPositionChanged;
  2136. /// <summary>
  2137. /// Called when selection start/end position is about to change.
  2138. /// </summary>
  2139. [SRDescription("DescriptionAttributeChartEvent_SelectionRangeChanging"),
  2140. SRCategory("CategoryAttributeCursor")]
  2141. public event EventHandler<CursorEventArgs> SelectionRangeChanging;
  2142. /// <summary>
  2143. /// Called when selection start/end position is changed.
  2144. /// </summary>
  2145. [SRDescription("DescriptionAttributeChartEvent_SelectionRangeChanged"),
  2146. SRCategory("CategoryAttributeCursor")]
  2147. public event EventHandler<CursorEventArgs> SelectionRangeChanged;
  2148. /// <summary>
  2149. /// Calls event delegate.
  2150. /// </summary>
  2151. /// <param name="arguments">Cursor event arguments.</param>
  2152. internal void OnCursorPositionChanging(CursorEventArgs arguments)
  2153. {
  2154. if(CursorPositionChanging != null)
  2155. {
  2156. CursorPositionChanging(this, arguments);
  2157. }
  2158. }
  2159. /// <summary>
  2160. /// Calls event delegate.
  2161. /// </summary>
  2162. /// <param name="arguments">Cursor event arguments.</param>
  2163. internal void OnCursorPositionChanged(CursorEventArgs arguments)
  2164. {
  2165. if(CursorPositionChanged != null)
  2166. {
  2167. CursorPositionChanged(this, arguments);
  2168. }
  2169. }
  2170. /// <summary>
  2171. /// Calls event delegate.
  2172. /// </summary>
  2173. /// <param name="arguments">Cursor event arguments.</param>
  2174. internal void OnSelectionRangeChanging(CursorEventArgs arguments)
  2175. {
  2176. if(SelectionRangeChanging != null)
  2177. {
  2178. SelectionRangeChanging(this, arguments);
  2179. }
  2180. }
  2181. /// <summary>
  2182. /// Calls event delegate.
  2183. /// </summary>
  2184. /// <param name="arguments">Cursor event arguments.</param>
  2185. internal void OnSelectionRangeChanged(CursorEventArgs arguments)
  2186. {
  2187. if(SelectionRangeChanged != null)
  2188. {
  2189. SelectionRangeChanged(this, arguments);
  2190. }
  2191. }
  2192. #endregion
  2193. #region Axis data scaleView position/size changing events
  2194. /// <summary>
  2195. /// Called when axis scaleView position/size is about to change.
  2196. /// </summary>
  2197. [SRDescription("DescriptionAttributeChartEvent_AxisViewChanging"),
  2198. SRCategory("CategoryAttributeAxisView")]
  2199. public event EventHandler<ViewEventArgs> AxisViewChanging;
  2200. /// <summary>
  2201. /// Called when axis scaleView position/size is changed.
  2202. /// </summary>
  2203. [SRDescription("DescriptionAttributeChartEvent_AxisViewChanged"),
  2204. SRCategory("CategoryAttributeAxisView")]
  2205. public event EventHandler<ViewEventArgs> AxisViewChanged;
  2206. /// <summary>
  2207. /// Calls event delegate.
  2208. /// </summary>
  2209. /// <param name="arguments">Axis scaleView event arguments.</param>
  2210. internal void OnAxisViewChanging(ViewEventArgs arguments)
  2211. {
  2212. if(AxisViewChanging != null)
  2213. {
  2214. AxisViewChanging(this, arguments);
  2215. }
  2216. }
  2217. /// <summary>
  2218. /// Calls event delegate.
  2219. /// </summary>
  2220. /// <param name="arguments">Axis scaleView event arguments.</param>
  2221. internal void OnAxisViewChanged(ViewEventArgs arguments)
  2222. {
  2223. if(AxisViewChanged != null)
  2224. {
  2225. AxisViewChanged(this, arguments);
  2226. }
  2227. }
  2228. #endregion
  2229. #region Axis scroll bar events
  2230. /// <summary>
  2231. /// Called when axis scroll bar is used by user.
  2232. /// </summary>
  2233. [SRDescription("DescriptionAttributeChartEvent_AxisScrollBarClicked"),
  2234. SRCategory("CategoryAttributeAxisView")]
  2235. public event EventHandler<ScrollBarEventArgs> AxisScrollBarClicked;
  2236. /// <summary>
  2237. /// Calls event delegate.
  2238. /// </summary>
  2239. /// <param name="arguments">Axis scroll bar event arguments.</param>
  2240. internal void OnAxisScrollBarClicked(ScrollBarEventArgs arguments)
  2241. {
  2242. if(AxisScrollBarClicked != null)
  2243. {
  2244. AxisScrollBarClicked(this, arguments);
  2245. }
  2246. }
  2247. #endregion
  2248. #region Painting events
  2249. /// <summary>
  2250. /// Called when chart element is painted.
  2251. /// </summary>
  2252. [SRDescription("DescriptionAttributeChartEvent_PostPaint"),
  2253. SRCategory("CategoryAttributeAppearance")]
  2254. public event EventHandler<ChartPaintEventArgs> PostPaint;
  2255. /// <summary>
  2256. /// Called when chart element back ground is painted.
  2257. /// </summary>
  2258. [SRDescription("DescriptionAttributeChartEvent_PrePaint"),
  2259. SRCategory("CategoryAttributeAppearance")]
  2260. public event EventHandler<ChartPaintEventArgs> PrePaint;
  2261. /// <summary>
  2262. /// Fires when chart element backround must be drawn.
  2263. /// This event is fired for elements like: ChartPicture, ChartArea and Legend
  2264. /// </summary>
  2265. /// <param name="e">Event arguments.</param>
  2266. protected virtual void OnPrePaint(ChartPaintEventArgs e)
  2267. {
  2268. if(PrePaint != null)
  2269. {
  2270. PrePaint(this, e);
  2271. }
  2272. }
  2273. /// <summary>
  2274. /// Fires when chart element backround must be drawn.
  2275. /// This event is fired for elements like: ChartPicture, ChartArea and Legend
  2276. /// </summary>
  2277. /// <param name="e">Event arguments.</param>
  2278. internal void CallOnPrePaint(ChartPaintEventArgs e)
  2279. {
  2280. this.OnPrePaint(e);
  2281. }
  2282. /// <summary>
  2283. /// Fires when chart element must be drawn.
  2284. /// This event is fired for elements like: ChartPicture, ChartArea and Legend
  2285. /// </summary>
  2286. /// <param name="e">Event arguments.</param>
  2287. protected virtual void OnPostPaint(ChartPaintEventArgs e)
  2288. {
  2289. if(PostPaint != null)
  2290. {
  2291. PostPaint(this, e);
  2292. }
  2293. }
  2294. /// <summary>
  2295. /// Fires when chart element must be drawn.
  2296. /// This event is fired for elements like: ChartPicture, ChartArea and Legend
  2297. /// </summary>
  2298. /// <param name="e">Event arguments.</param>
  2299. internal void CallOnPostPaint(ChartPaintEventArgs e)
  2300. {
  2301. this.OnPostPaint(e);
  2302. }
  2303. #endregion
  2304. #region Customize event
  2305. /// <summary>
  2306. /// Fires just before the chart image is drawn. Use this event to customize the chart picture.
  2307. /// </summary>
  2308. [
  2309. SRDescription("DescriptionAttributeChartEvent_Customize")
  2310. ]
  2311. public event EventHandler Customize;
  2312. /// <summary>
  2313. /// Fires when all chart data is prepared to be customized before drawing.
  2314. /// </summary>
  2315. [
  2316. SRDescription("DescriptionAttributeChart_OnCustomize")
  2317. ]
  2318. protected virtual void OnCustomize()
  2319. {
  2320. if(Customize != null)
  2321. {
  2322. Customize(this, EventArgs.Empty);
  2323. }
  2324. }
  2325. /// <summary>
  2326. /// Fires when all chart data is prepared to be customized before drawing.
  2327. /// </summary>
  2328. internal void CallOnCustomize()
  2329. {
  2330. this.OnCustomize();
  2331. }
  2332. /// <summary>
  2333. /// Use this event to customize chart legend.
  2334. /// </summary>
  2335. [
  2336. SRDescription("DescriptionAttributeChartEvent_CustomizeLegend")
  2337. ]
  2338. public event EventHandler<CustomizeLegendEventArgs> CustomizeLegend;
  2339. /// <summary>
  2340. /// Fires when all chart data is prepared to be customized before drawing.
  2341. /// </summary>
  2342. [
  2343. SRDescription("DescriptionAttributeChart_OnCustomizeLegend")
  2344. ]
  2345. protected virtual void OnCustomizeLegend(LegendItemsCollection legendItems, string legendName)
  2346. {
  2347. if (CustomizeLegend != null)
  2348. {
  2349. CustomizeLegend(this, new CustomizeLegendEventArgs(legendItems, legendName));
  2350. }
  2351. }
  2352. /// <summary>
  2353. /// Fires when all chart data is prepared to be customized before drawing.
  2354. /// </summary>
  2355. internal void CallOnCustomizeLegend(LegendItemsCollection legendItems, string legendName)
  2356. {
  2357. this.OnCustomizeLegend(legendItems, legendName);
  2358. }
  2359. #endregion
  2360. #region Annotation events
  2361. /// <summary>
  2362. /// Fires when annotation text was changed.
  2363. /// </summary>
  2364. [
  2365. SRDescription("DescriptionAttributeChartEvent_AnnotationTextChanged"),
  2366. SRCategory("CategoryAttributeAnnotation")
  2367. ]
  2368. public event EventHandler AnnotationTextChanged;
  2369. /// <summary>
  2370. /// Fires when annotation text is changed.
  2371. /// </summary>
  2372. /// <param name="annotation">Annotation which text was changed.</param>
  2373. internal void OnAnnotationTextChanged(Annotation annotation)
  2374. {
  2375. if(AnnotationTextChanged != null)
  2376. {
  2377. AnnotationTextChanged(annotation, EventArgs.Empty);
  2378. }
  2379. }
  2380. /// <summary>
  2381. /// Fires when selected annotation changes.
  2382. /// </summary>
  2383. [
  2384. SRDescription("DescriptionAttributeChartEvent_AnnotationSelectionChanged"),
  2385. SRCategory("CategoryAttributeAnnotation")
  2386. ]
  2387. public event EventHandler AnnotationSelectionChanged;
  2388. /// <summary>
  2389. /// Fires when annotation position was changed.
  2390. /// </summary>
  2391. [
  2392. SRDescription("DescriptionAttributeChartEvent_AnnotationPositionChanged"),
  2393. SRCategory("CategoryAttributeAnnotation")
  2394. ]
  2395. public event EventHandler AnnotationPositionChanged;
  2396. /// <summary>
  2397. /// Fires when annotation position is changing.
  2398. /// </summary>
  2399. [
  2400. SRDescription("DescriptionAttributeChartEvent_AnnotationPositionChanging"),
  2401. SRCategory("CategoryAttributeAnnotation")
  2402. ]
  2403. public event EventHandler<AnnotationPositionChangingEventArgs> AnnotationPositionChanging;
  2404. /// <summary>
  2405. /// Fires when annotation is placed by the user on the chart.
  2406. /// </summary>
  2407. [
  2408. SRDescription("DescriptionAttributeChartEvent_AnnotationPlaced"),
  2409. SRCategory("CategoryAttributeAnnotation")
  2410. ]
  2411. public event EventHandler AnnotationPlaced;
  2412. /// <summary>
  2413. /// Fires when annotation is placed by the user on the chart.
  2414. /// </summary>
  2415. /// <param name="annotation">Annotation which was placed.</param>
  2416. internal void OnAnnotationPlaced(Annotation annotation)
  2417. {
  2418. if(AnnotationPlaced != null)
  2419. {
  2420. AnnotationPlaced(annotation, EventArgs.Empty);
  2421. }
  2422. }
  2423. /// <summary>
  2424. /// Fires when selected annotation changes.
  2425. /// </summary>
  2426. /// <param name="annotation">Annotation which have it's selection changed.</param>
  2427. internal void OnAnnotationSelectionChanged(Annotation annotation)
  2428. {
  2429. if(AnnotationSelectionChanged != null)
  2430. {
  2431. AnnotationSelectionChanged(annotation, EventArgs.Empty);
  2432. }
  2433. }
  2434. /// <summary>
  2435. /// Fires when annotation position was changed.
  2436. /// </summary>
  2437. /// <param name="annotation">Annotation which have it's position changed.</param>
  2438. internal void OnAnnotationPositionChanged(Annotation annotation)
  2439. {
  2440. if(AnnotationPositionChanged != null)
  2441. {
  2442. AnnotationPositionChanged(annotation, EventArgs.Empty);
  2443. }
  2444. }
  2445. /// <summary>
  2446. /// Fires when annotation position is changing.
  2447. /// </summary>
  2448. /// <param name="args">Event arguments.</param>
  2449. /// <returns>True if event was processed.</returns>
  2450. internal bool OnAnnotationPositionChanging(ref AnnotationPositionChangingEventArgs args)
  2451. {
  2452. if(AnnotationPositionChanging != null)
  2453. {
  2454. AnnotationPositionChanging(args.Annotation, args);
  2455. return true;
  2456. }
  2457. return false;
  2458. }
  2459. #endregion
  2460. #region Control DataBind method
  2461. /// <summary>
  2462. /// Data binds control to the selected data source.
  2463. /// </summary>
  2464. public void DataBind()
  2465. {
  2466. this.chartPicture.DataBind();
  2467. }
  2468. /// <summary>
  2469. /// Aligns data points using their axis labels.
  2470. /// </summary>
  2471. public void AlignDataPointsByAxisLabel()
  2472. {
  2473. this.chartPicture.AlignDataPointsByAxisLabel(false, PointSortOrder.Ascending);
  2474. }
  2475. /// <summary>
  2476. /// Aligns data points using their axis labels.
  2477. /// </summary>
  2478. /// <param name="series">Comma separated list of series that should be aligned by axis label.</param>
  2479. public void AlignDataPointsByAxisLabel(string series)
  2480. {
  2481. //Check arguments
  2482. if (series == null)
  2483. throw new ArgumentNullException("series");
  2484. // Create list of series
  2485. ArrayList seriesList = new ArrayList();
  2486. string[] seriesNames = series.Split(',');
  2487. foreach(string name in seriesNames)
  2488. {
  2489. seriesList.Add(this.Series[name.Trim()]);
  2490. }
  2491. // Align series
  2492. this.chartPicture.AlignDataPointsByAxisLabel(seriesList, false, PointSortOrder.Ascending);
  2493. }
  2494. /// <summary>
  2495. /// Aligns data points using their axis labels.
  2496. /// </summary>
  2497. /// <param name="series">Comma separated list of series that should be aligned by axis label.</param>
  2498. /// <param name="sortingOrder">Points sorting order by axis labels.</param>
  2499. public void AlignDataPointsByAxisLabel(string series, PointSortOrder sortingOrder)
  2500. {
  2501. //Check arguments
  2502. if (series == null)
  2503. throw new ArgumentNullException("series");
  2504. // Create list of series
  2505. ArrayList seriesList = new ArrayList();
  2506. string[] seriesNames = series.Split(',');
  2507. foreach(string name in seriesNames)
  2508. {
  2509. seriesList.Add(this.Series[name.Trim()]);
  2510. }
  2511. // Align series
  2512. this.chartPicture.AlignDataPointsByAxisLabel(seriesList, true, sortingOrder);
  2513. }
  2514. /// <summary>
  2515. /// Aligns data points using their axis labels.
  2516. /// </summary>
  2517. /// <param name="sortingOrder">Points sorting order by axis labels.</param>
  2518. public void AlignDataPointsByAxisLabel(PointSortOrder sortingOrder)
  2519. {
  2520. this.chartPicture.AlignDataPointsByAxisLabel(true, sortingOrder);
  2521. }
  2522. /// <summary>
  2523. /// Automatically creates and binds series to specified data table.
  2524. /// Each column of the table becomes a Y value in a separate series.
  2525. /// Series X value field may also be provided.
  2526. /// </summary>
  2527. /// <param name="dataSource">Data source.</param>
  2528. /// <param name="xField">Name of the field for series X values.</param>
  2529. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  2530. Justification = "X is a cartesian coordinate and well understood")]
  2531. public void DataBindTable(
  2532. IEnumerable dataSource,
  2533. string xField)
  2534. {
  2535. this.chartPicture.DataBindTable(
  2536. dataSource,
  2537. xField);
  2538. }
  2539. /// <summary>
  2540. /// Automatically creates and binds series to specified data table.
  2541. /// Each column of the table becomes a Y value in a separate series.
  2542. /// </summary>
  2543. /// <param name="dataSource">Data source.</param>
  2544. public void DataBindTable(IEnumerable dataSource)
  2545. {
  2546. this.chartPicture.DataBindTable(
  2547. dataSource,
  2548. String.Empty);
  2549. }
  2550. /// <summary>
  2551. /// Data bind chart to the table. Series will be automatically added to the chart depending ont
  2552. /// yhe number of unique values in the seriesGroupByField column of the data source.
  2553. /// Data source can be the Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  2554. /// </summary>
  2555. /// <param name="dataSource">Data source.</param>
  2556. /// <param name="seriesGroupByField">Name of the field used to group data into series.</param>
  2557. /// <param name="xField">Name of the field for X values.</param>
  2558. /// <param name="yFields">Comma separated name(s) of the field(s) for Y value(s).</param>
  2559. /// <param name="otherFields">Other point properties binding rule in format: PointProperty=Field[{Format}] [,PointProperty=Field[{Format}]]. For example: "Tooltip=Price{C1},Url=WebSiteName".</param>
  2560. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  2561. Justification = "X and Y are cartesian coordinates and well understood")]
  2562. public void DataBindCrossTable(
  2563. IEnumerable dataSource,
  2564. string seriesGroupByField,
  2565. string xField,
  2566. string yFields,
  2567. string otherFields)
  2568. {
  2569. this.chartPicture.DataBindCrossTab(
  2570. dataSource,
  2571. seriesGroupByField,
  2572. xField,
  2573. yFields,
  2574. otherFields,
  2575. false,
  2576. PointSortOrder.Ascending);
  2577. }
  2578. /// <summary>
  2579. /// Data bind chart to the table. Series will be automatically added to the chart depending ont
  2580. /// yhe number of unique values in the seriesGroupByField column of the data source.
  2581. /// Data source can be the Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  2582. /// </summary>
  2583. /// <param name="dataSource">Data source.</param>
  2584. /// <param name="seriesGroupByField">Name of the field used to group data into series.</param>
  2585. /// <param name="xField">Name of the field for X values.</param>
  2586. /// <param name="yFields">Comma separated name(s) of the field(s) for Y value(s).</param>
  2587. /// <param name="otherFields">Other point properties binding rule in format: PointProperty=Field[{Format}] [,PointProperty=Field[{Format}]]. For example: "Tooltip=Price{C1},Url=WebSiteName".</param>
  2588. /// <param name="sortingOrder">Series will be sorted by group field values in specified order.</param>
  2589. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  2590. Justification = "X and Y are cartesian coordinates and well understood")]
  2591. public void DataBindCrossTable(
  2592. IEnumerable dataSource,
  2593. string seriesGroupByField,
  2594. string xField,
  2595. string yFields,
  2596. string otherFields,
  2597. PointSortOrder sortingOrder)
  2598. {
  2599. this.chartPicture.DataBindCrossTab(
  2600. dataSource,
  2601. seriesGroupByField,
  2602. xField,
  2603. yFields,
  2604. otherFields,
  2605. true,
  2606. sortingOrder);
  2607. }
  2608. #endregion
  2609. #region Special Extension Methods and Properties
  2610. /// <summary>
  2611. /// Gets the requested chart service.
  2612. /// </summary>
  2613. /// <param name="serviceType">AxisName of requested service.</param>
  2614. /// <returns>Instance of the service or null if it can't be found.</returns>
  2615. public new object GetService(Type serviceType)
  2616. {
  2617. // Check arguments
  2618. if (serviceType == null)
  2619. throw new ArgumentNullException("serviceType");
  2620. object service = null;
  2621. if(serviceContainer != null)
  2622. {
  2623. service = serviceContainer.GetService(serviceType);
  2624. }
  2625. if(service == null)
  2626. {
  2627. base.GetService(serviceType);
  2628. }
  2629. return service;
  2630. }
  2631. /// <summary>
  2632. /// Called when a numeric value has to be converted to a string.
  2633. /// </summary>
  2634. [SRDescription("DescriptionAttributeChartEvent_PrePaint")]
  2635. public event EventHandler<FormatNumberEventArgs> FormatNumber;
  2636. /// <summary>
  2637. /// Utility method for firing the FormatNumber event. Allows it to be
  2638. /// handled via OnFormatNumber as is the usual pattern as well as via
  2639. /// CallOnFormatNumber.
  2640. /// </summary>
  2641. /// <param name="caller">Event caller. Can be ChartPicture, ChartArea or Legend objects.</param>
  2642. /// <param name="e">Event arguemtns</param>
  2643. private void OnFormatNumber(object caller, FormatNumberEventArgs e)
  2644. {
  2645. if (FormatNumber != null)
  2646. {
  2647. FormatNumber(caller, e);
  2648. }
  2649. }
  2650. /// <summary>
  2651. /// Called when a numeric value has to be converted to a string.
  2652. /// </summary>
  2653. /// <param name="e">Event arguments.</param>
  2654. protected virtual void OnFormatNumber(FormatNumberEventArgs e)
  2655. {
  2656. OnFormatNumber(this, e);
  2657. }
  2658. /// <summary>
  2659. /// Called when a numeric value has to be converted to a string.
  2660. /// </summary>
  2661. /// <param name="caller">Event caller. Can be ChartPicture, ChartArea or Legend objects.</param>
  2662. /// <param name="e">Event arguments.</param>
  2663. internal void CallOnFormatNumber(object caller, FormatNumberEventArgs e)
  2664. {
  2665. this.OnFormatNumber(caller, e);
  2666. }
  2667. #endregion
  2668. #region Accessibility
  2669. #if ACCESSIBLE
  2670. // Current chart accessibility object
  2671. private ChartAccessibleObject _chartAccessibleObject = null;
  2672. /// <summary>
  2673. /// Overridden to return the custom AccessibleObject for the entire chart.
  2674. /// </summary>
  2675. /// <returns>Chart accessibility object.</returns>
  2676. protected override AccessibleObject CreateAccessibilityInstance()
  2677. {
  2678. if (this._chartAccessibleObject == null)
  2679. {
  2680. this._chartAccessibleObject = new ChartAccessibleObject(this);
  2681. }
  2682. return this._chartAccessibleObject;
  2683. }
  2684. /// <summary>
  2685. /// Reset accessibility object children.
  2686. /// </summary>
  2687. private void ResetAccessibilityObject()
  2688. {
  2689. if (this._chartAccessibleObject != null)
  2690. {
  2691. this._chartAccessibleObject.ResetChildren();
  2692. }
  2693. }
  2694. #endif
  2695. #endregion // Accessibility
  2696. #region IDisposable override
  2697. /// <summary>
  2698. /// Disposing control resourses
  2699. /// </summary>
  2700. protected override void Dispose(bool disposing)
  2701. {
  2702. // call first because font cache
  2703. base.Dispose(disposing);
  2704. if (disposing)
  2705. {
  2706. // Dispose managed objects here
  2707. if (_imageLoader != null)
  2708. {
  2709. _imageLoader.Dispose();
  2710. _imageLoader = null;
  2711. }
  2712. if (_namedImages != null)
  2713. {
  2714. _namedImages.Dispose();
  2715. _namedImages = null;
  2716. }
  2717. if (_chartTypeRegistry != null)
  2718. {
  2719. _chartTypeRegistry.Dispose();
  2720. _chartTypeRegistry = null;
  2721. }
  2722. if (serviceContainer != null)
  2723. {
  2724. serviceContainer.RemoveService(typeof(Chart));
  2725. serviceContainer.Dispose();
  2726. serviceContainer = null;
  2727. }
  2728. // Dispose selection manager
  2729. if (selection != null)
  2730. {
  2731. selection.Dispose();
  2732. selection = null;
  2733. }
  2734. // Dispose print manager
  2735. if (_printingManager != null)
  2736. {
  2737. _printingManager.Dispose();
  2738. _printingManager = null;
  2739. }
  2740. // Dispoase buffer
  2741. if (paintBufferBitmap != null)
  2742. {
  2743. paintBufferBitmap.Dispose();
  2744. paintBufferBitmap = null;
  2745. }
  2746. if (paintBufferBitmapGraphics != null)
  2747. {
  2748. paintBufferBitmapGraphics.Dispose();
  2749. paintBufferBitmapGraphics = null;
  2750. }
  2751. }
  2752. base.Dispose(disposing);
  2753. //The chart picture and datamanager will be the last to be disposed
  2754. if (disposing)
  2755. {
  2756. if (_dataManager != null)
  2757. {
  2758. _dataManager.Dispose();
  2759. _dataManager = null;
  2760. }
  2761. if (chartPicture != null)
  2762. {
  2763. chartPicture.Dispose();
  2764. chartPicture = null;
  2765. }
  2766. }
  2767. }
  2768. #endregion
  2769. }
  2770. #region Customize event delegate
  2771. /// <summary>
  2772. /// Chart legend customize events arguments
  2773. /// </summary>
  2774. public class CustomizeLegendEventArgs : EventArgs
  2775. {
  2776. private LegendItemsCollection _legendItems = null;
  2777. private string _legendName = "";
  2778. /// <summary>
  2779. /// Default construvtor is not accessible
  2780. /// </summary>
  2781. private CustomizeLegendEventArgs()
  2782. {
  2783. }
  2784. /// <summary>
  2785. /// Customize legend event arguments constructor
  2786. /// </summary>
  2787. /// <param name="legendItems">Legend items collection.</param>
  2788. public CustomizeLegendEventArgs(LegendItemsCollection legendItems)
  2789. {
  2790. this._legendItems = legendItems;
  2791. }
  2792. /// <summary>
  2793. /// Customize legend event arguments constructor
  2794. /// </summary>
  2795. /// <param name="legendItems">Legend items collection.</param>
  2796. /// <param name="legendName">Legend name.</param>
  2797. public CustomizeLegendEventArgs(LegendItemsCollection legendItems, string legendName)
  2798. {
  2799. this._legendItems = legendItems;
  2800. this._legendName = legendName;
  2801. }
  2802. /// <summary>
  2803. /// Legend name.
  2804. /// </summary>
  2805. public string LegendName
  2806. {
  2807. get
  2808. {
  2809. return _legendName;
  2810. }
  2811. }
  2812. /// <summary>
  2813. /// Legend items collection.
  2814. /// </summary>
  2815. public LegendItemsCollection LegendItems
  2816. {
  2817. get
  2818. {
  2819. return _legendItems;
  2820. }
  2821. }
  2822. }
  2823. #endregion
  2824. }