Click here to Skip to main content
15,884,237 members
Articles / Desktop Programming / MFC

High-speed Charting Control

Rate me:
Please Sign up or sign in to vote.
4.95/5 (327 votes)
13 Jul 2010CPOL35 min read 4.2M   100.5K   787  
A flexible charting control to display 2D data
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ChartDemo: E:/Sources Misc/ChartDemo/ChartCtrl/ChartSerieBase.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>E:/Sources Misc/ChartDemo/ChartCtrl/ChartSerieBase.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> *      ChartSerieBase.h</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> *      Written by C�dric Moonen (cedric_moonen@hotmail.com)</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> *      This code may be used for any non-commercial and commercial purposes in a compiled form.</span>
<a name="l00010"></a>00010 <span class="comment"> *      The code may be redistributed as long as it remains unmodified and providing that the </span>
<a name="l00011"></a>00011 <span class="comment"> *      author name and this disclaimer remain intact. The sources can be modified WITH the author </span>
<a name="l00012"></a>00012 <span class="comment"> *      consent only.</span>
<a name="l00013"></a>00013 <span class="comment"> *      </span>
<a name="l00014"></a>00014 <span class="comment"> *      This code is provided without any garanties. I cannot be held responsible for the damage or</span>
<a name="l00015"></a>00015 <span class="comment"> *      the loss of time it causes. Use it at your own risks</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> *      An e-mail to notify me that you are using this code is appreciated also.</span>
<a name="l00018"></a>00018 <span class="comment"> *</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> */</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#pragma once</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="preprocessor">#if _MSC_VER &gt; 1000</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#pragma once</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#endif // _MSC_VER &gt; 1000</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "ChartSerie.h"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "ChartAxis.h"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include "ChartPointsArray.h"</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include "ChartLabel.h"</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include "ChartBalloonLabel.h"</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include "ChartSeriesMouseListener.h"</span>
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "ChartString.h"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "PointsOrdering.h"</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="keyword">class </span><a class="code" href="class_c_chart_legend.html" title="This class is responsible for the legend displayed on the control.">CChartLegend</a>;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 
<a name="l00043"></a>00043 
<a name="l00050"></a>00050 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00051"></a><a class="code" href="class_c_chart_serie_base.html">00051</a> <span class="keyword">class </span><a class="code" href="class_c_chart_serie_base.html" title="Base class for all series of the control.">CChartSerieBase</a> : <span class="keyword">public</span> <a class="code" href="class_c_chart_serie.html" title="Abstract class that provides a common &amp;quot;interface&amp;quot; for all series in the...">CChartSerie</a>
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053         <span class="keyword">friend</span> <a class="code" href="class_c_chart_ctrl.html" title="The main chart control class.">CChartCtrl</a>;
<a name="l00054"></a>00054         <span class="keyword">friend</span> <a class="code" href="class_c_chart_legend.html" title="This class is responsible for the legend displayed on the control.">CChartLegend</a>;
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="keyword">public</span>:
<a name="l00058"></a>00058         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#21c22b7767a46f8f09586a2e8b32f917" title="Adds a single data point to the series.">AddPoint</a>(<span class="keyword">const</span> T&amp; newPoint);
<a name="l00060"></a>00060 
<a name="l00067"></a>00067         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#7ba5a7e254d485351ce94c2d38240264" title="Adds an array of points to the series.">AddPoints</a>(T* pPoints, <span class="keywordtype">unsigned</span> Count);
<a name="l00069"></a>00069 
<a name="l00073"></a>00073         <span class="keyword">const</span> T&amp; <a class="code" href="class_c_chart_serie_base.html#11a13d2c2423cdd7637cdd1586ee2013" title="Retrieves the point at the specified index.">GetPoint</a>(<span class="keywordtype">unsigned</span> index) <span class="keyword">const</span>;
<a name="l00075"></a>00075 
<a name="l00082"></a>00082         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#0bff2bc0c029e24f5363f8dee006509e" title="Sets an array of points to the series.">SetPoints</a>(T* pPoints, <span class="keywordtype">unsigned</span> Count);
<a name="l00084"></a>00084         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#adb90c3e0b0b6ac99fefed5ae47d5a13" title="Removes a certain amount of points from the begining of the series.">RemovePointsFromBegin</a>(<span class="keywordtype">unsigned</span> Count);
<a name="l00086"></a>00086         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#f9686a2cd7d6ae05d4e1194d54681529" title="Removes a certain amount of points from the end of the series.">RemovePointsFromEnd</a>(<span class="keywordtype">unsigned</span> Count);
<a name="l00088"></a>00088         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#c21ed91525137746205c4cbf20a9f492" title="Removes all points from the series.">ClearSerie</a>();
<a name="l00089"></a>00089 
<a name="l00091"></a><a class="code" href="class_c_chart_serie_base.html#1413ed4eec375dc4e37a635373ec1f3b">00091</a>         <span class="keywordtype">unsigned</span> <a class="code" href="class_c_chart_serie_base.html#1413ed4eec375dc4e37a635373ec1f3b" title="Returns the number of points in the series.">GetPointsCount</a>()<span class="keyword"> const  </span>{ <span class="keywordflow">return</span> <a class="code" href="class_c_chart_serie_base.html#05e45c83cd36d4253a0e5a32b43ebd87" title="The helper class containing all the data points.">m_vPoints</a>.GetPointsCount(); }
<a name="l00092"></a>00092 
<a name="l00094"></a>00094 
<a name="l00102"></a>00102         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_serie_base.html#8ecff476195375224e976b9641e1b5de" title="Retrieves the minimum and maxium Y values of the series.">GetSerieYMinMax</a>(<span class="keywordtype">double</span>&amp; Min, <span class="keywordtype">double</span>&amp; Max)  <span class="keyword">const</span>;
<a name="l00104"></a>00104 
<a name="l00112"></a>00112         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_serie_base.html#6e82d73342e06886109ef21c8e857d70" title="Retrieves the minimum and maxium X values of the series.">GetSerieXMinMax</a>(<span class="keywordtype">double</span>&amp; Min, <span class="keywordtype">double</span>&amp; Max)  <span class="keyword">const</span>;
<a name="l00114"></a>00114 
<a name="l00122"></a>00122         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_serie_base.html#91098c0d9e2d419783fad0a6c9da34c9" title="Retrieves the minimum and maxium screen X values of the series.">GetSerieXScreenMinMax</a>(<span class="keywordtype">double</span>&amp; Min, <span class="keywordtype">double</span>&amp; Max)  <span class="keyword">const</span>;
<a name="l00124"></a>00124 
<a name="l00132"></a>00132         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_serie_base.html#e8058b76f76ecd047aeae2e50adef491" title="Retrieves the minimum and maxium screen Y values of the series.">GetSerieYScreenMinMax</a>(<span class="keywordtype">double</span>&amp; Min, <span class="keywordtype">double</span>&amp; Max)  <span class="keyword">const</span>;
<a name="l00133"></a>00133 
<a name="l00135"></a>00135 
<a name="l00143"></a>00143         <a class="code" href="class_c_chart_balloon_label.html" title="Specialization of the CChartLabel to display a balloon label.">CChartBalloonLabel&lt;T&gt;</a>* <a class="code" href="class_c_chart_serie_base.html#5662711d8d1b5d90929a2def01e43205" title="Creates and attaches a balloon label on a point of the series.">CreateBalloonLabel</a>(<span class="keywordtype">unsigned</span> uPointIndex, <span class="keyword">const</span> TChartString&amp; strLabelText);
<a name="l00145"></a>00145 
<a name="l00156"></a>00156         <a class="code" href="class_c_chart_balloon_label.html" title="Specialization of the CChartLabel to display a balloon label.">CChartBalloonLabel&lt;T&gt;</a>* <a class="code" href="class_c_chart_serie_base.html#5662711d8d1b5d90929a2def01e43205" title="Creates and attaches a balloon label on a point of the series.">CreateBalloonLabel</a>(<span class="keywordtype">unsigned</span> uPointIndex, <a class="code" href="class_c_chart_label_provider.html" title="Interface which should be implemented in order to provide text to a label.">CChartLabelProvider&lt;T&gt;</a>* pLabelProvider);
<a name="l00158"></a>00158 
<a name="l00164"></a>00164         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#54d5979e76985cb64506a85857c59cec" title="Attaches a custom label on a point of the series.">AttachCustomLabel</a>(<span class="keywordtype">unsigned</span> uPointIndex, <a class="code" href="class_c_chart_label.html" title="Draws a label containing some text which is attached to a point of a series.">CChartLabel&lt;T&gt;</a>* pLabel);
<a name="l00165"></a>00165 
<a name="l00167"></a>00167         <a class="code" href="class_c_chart_serie_base.html#5f6c288ebecbbe09cfdd6df67ac4061f" title="Constructor.">CChartSerieBase</a>(<a class="code" href="class_c_chart_ctrl.html" title="The main chart control class.">CChartCtrl</a>* pParent);
<a name="l00169"></a>00169         <span class="keyword">virtual</span> <a class="code" href="class_c_chart_serie_base.html#82f7220fa2eb6ca60e661d71dca30546" title="Destructor.">~CChartSerieBase</a>();
<a name="l00170"></a>00170 
<a name="l00172"></a>00172 
<a name="l00179"></a>00179         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#764966e36ffadada4c8d09281c6933e3" title="Specifies how the points should be ordered in the series.">SetSeriesOrdering</a>(PointsOrdering newOrdering);
<a name="l00180"></a>00180 
<a name="l00182"></a>00182 
<a name="l00187"></a>00187         CPoint <a class="code" href="class_c_chart_serie_base.html#3b45afc661ca9d5b40f645acee320e52" title="Retrieves the screen point of a specific data point.">GetPointScreenCoord</a>(<span class="keywordtype">unsigned</span> uPointIndex);
<a name="l00188"></a>00188 
<a name="l00190"></a>00190 
<a name="l00194"></a>00194         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#89ba6e69607e682ccbe173e097c6f422" title="Register a series mouse listener on this series.">RegisterMouseListener</a>(<a class="code" href="class_c_chart_series_mouse_listener.html">CChartSeriesMouseListener&lt;T&gt;</a>* pListener);
<a name="l00196"></a>00196         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_serie_base.html#91270d888b9c8d2aa5b36b3a86147b41" title="Unregister the series mouse listener for this series.">UnregisterMouseListener</a>();
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 <span class="keyword">protected</span>:
<a name="l00200"></a>00200 
<a name="l00208"></a>00208         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_serie_base.html#a5674d16c56302654665d7839ae23665" title="Returns the first and last visible points of the series.">GetVisiblePoints</a>(<span class="keywordtype">unsigned</span>&amp; uFirst, <span class="keywordtype">unsigned</span>&amp; uLast) <span class="keyword">const</span>;
<a name="l00209"></a>00209 
<a name="l00211"></a>00211         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_serie_base.html#cbb5e34bc22e6c9730987db79aba0cae" title="Called by the control to check if an event occured on the series.">OnMouseEvent</a>(<a class="code" href="class_c_chart_mouse_listener.html#cffa1073dca632eca72f7339ecb350d7" title="Enumeration listing the type of mouse events.">CChartMouseListener::MouseEvent</a> mouseEvent, 
<a name="l00212"></a>00212                                         <span class="keyword">const</span> CPoint&amp; screenPoint);
<a name="l00213"></a>00213 
<a name="l00215"></a><a class="code" href="class_c_chart_serie_base.html#05e45c83cd36d4253a0e5a32b43ebd87">00215</a>         <a class="code" href="class_c_chart_points_array.html" title="Manages an array of points which supports fast resizing.">CChartPointsArray&lt;T&gt;</a> <a class="code" href="class_c_chart_serie_base.html#05e45c83cd36d4253a0e5a32b43ebd87" title="The helper class containing all the data points.">m_vPoints</a>;
<a name="l00217"></a><a class="code" href="class_c_chart_serie_base.html#4f39d97ff9a05fdb4ff6da33f4149740">00217</a>         <span class="keywordtype">unsigned</span> <a class="code" href="class_c_chart_serie_base.html#4f39d97ff9a05fdb4ff6da33f4149740" title="Index of the last point drawn.">m_uLastDrawnPoint</a>;             
<a name="l00218"></a>00218 
<a name="l00219"></a>00219 <span class="keyword">private</span>:
<a name="l00221"></a>00221         <span class="keywordtype">void</span> DrawLabels(CDC* pDC);
<a name="l00222"></a>00222 
<a name="l00223"></a>00223         <span class="keyword">typedef</span> std::map&lt;unsigned, CChartLabel&lt;T&gt;*&gt; TLabelMap;
<a name="l00225"></a>00225         TLabelMap m_mapLabels;
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         <a class="code" href="class_c_chart_series_mouse_listener.html">CChartSeriesMouseListener&lt;T&gt;</a>* m_pMouseListener;
<a name="l00228"></a>00228 };
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 <span class="preprocessor">#include "ChartSerieBase.inl"</span>
<a name="l00231"></a>00231 
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Jan 17 13:33:10 2010 for ChartDemo by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Belgium Belgium
I am a 29 years old guy and I live with my girlfriend in Hoegaarden, little city from Belgium well known for its white beer Smile | :) .
I studied as an industrial engineer in electronics but I oriented myself more towards software development when I started to work.
Currently I am working in a research centre in mechatronica. I mainly develop in C++ but I also do a bit of Java.
When I have so spare time, I like to read (mainly fantasy) and play electric guitar.

Comments and Discussions