Click here to Skip to main content
15,860,861 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.1M   99.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/ChartBarSerie.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/ChartBarSerie.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"> *      ChartBarSerie.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><span class="preprocessor">#include "ChartXYSerie.h"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "ChartGradient.h"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;list&gt;</span>
<a name="l00026"></a>00026 
<a name="l00028"></a>00028 
<a name="l00038"></a><a class="code" href="class_c_chart_bar_serie.html">00038</a> <span class="keyword">class </span><a class="code" href="class_c_chart_bar_serie.html" title="Specialization of a CChartSerie to display a bars series.">CChartBarSerie</a> : <span class="keyword">public</span> <a class="code" href="class_c_chart_x_y_serie.html" title="Specialization of a CChartSerieBase for series having data with an X and an Y value...">CChartXYSerie</a>
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 <span class="keyword">public</span>:
<a name="l00042"></a>00042         <a class="code" href="class_c_chart_bar_serie.html#05cae99f4f8c3c413913f0ee55f1cddc" title="Constructor.">CChartBarSerie</a>(<a class="code" href="class_c_chart_ctrl.html" title="The main chart control class.">CChartCtrl</a>* pParent);
<a name="l00044"></a>00044         <a class="code" href="class_c_chart_bar_serie.html#f17c82f287b9e3bdcb0bfb44740c085b" title="Destructor.">~CChartBarSerie</a>();
<a name="l00045"></a>00045 
<a name="l00047"></a>00047         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#20ce485665c27c0b9a645e77721da93c" title="Specifies if the bars are vertical or horizontal.">SetHorizontal</a>(<span class="keywordtype">bool</span> bHorizontal);
<a name="l00049"></a><a class="code" href="class_c_chart_bar_serie.html#870117e88804601968a15176b5b00625">00049</a>         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_bar_serie.html#870117e88804601968a15176b5b00625" title="Returns true if bars are horizontal, false otherwise.">GetHorizontal</a>()<span class="keyword"> const                </span>{ <span class="keywordflow">return</span> m_bHorizontal; }
<a name="l00050"></a>00050 
<a name="l00052"></a>00052         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#f936ce9f2e08c89e3e1fdee221fdd2e9" title="Sets the bars border color.">SetBorderColor</a>(COLORREF BorderColor);
<a name="l00054"></a><a class="code" href="class_c_chart_bar_serie.html#30b9d6b27438a8040cc40d68e7ff74ae">00054</a>         COLORREF <a class="code" href="class_c_chart_bar_serie.html#30b9d6b27438a8040cc40d68e7ff74ae" title="Returns the bars border color.">GetBorderColor</a>()<span class="keyword"> const                    </span>{ <span class="keywordflow">return</span> m_BorderColor; }
<a name="l00056"></a>00056         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#d106f77a1fca397d7cf091b9322bbf84" title="Sets the bars border width.">SetBorderWidth</a>(<span class="keywordtype">int</span> Width);
<a name="l00058"></a><a class="code" href="class_c_chart_bar_serie.html#1b3e0cb1970bb22e045628780a6218ae">00058</a>         <span class="keywordtype">int</span>  <a class="code" href="class_c_chart_bar_serie.html#1b3e0cb1970bb22e045628780a6218ae" title="Returns the bars border width.">GetBorderWidth</a>()<span class="keyword"> const             </span>{ <span class="keywordflow">return</span> m_iBorderWidth;  }
<a name="l00060"></a>00060         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#47ed2782d775df69aa5018a85f44ed41" title="Sets the bars width (in pixels).">SetBarWidth</a>(<span class="keywordtype">int</span> Width);
<a name="l00062"></a><a class="code" href="class_c_chart_bar_serie.html#8e4ab7a0af3097d935922f12ba9c4f3d">00062</a>         <span class="keywordtype">int</span>  <a class="code" href="class_c_chart_bar_serie.html#8e4ab7a0af3097d935922f12ba9c4f3d" title="Returns the bars width (in pixels).">GetBarWidth</a>()<span class="keyword"> const                </span>{ <span class="keywordflow">return</span> m_iBarWidth;  }
<a name="l00063"></a>00063 
<a name="l00065"></a>00065 
<a name="l00069"></a>00069         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#6d3435c3aed16932f8e7eff77dccdd15" title="Set the group Id of the series.">SetGroupId</a>(<span class="keywordtype">unsigned</span> GroupId);
<a name="l00071"></a><a class="code" href="class_c_chart_bar_serie.html#49f2d1b1359904abbdc526e2f0ef1f79">00071</a>         <span class="keywordtype">unsigned</span> <a class="code" href="class_c_chart_bar_serie.html#49f2d1b1359904abbdc526e2f0ef1f79" title="Returns the group Id of the series.">GetGroupId</a>()<span class="keyword"> const                     </span>{ <span class="keywordflow">return</span> m_uGroupId;    }
<a name="l00072"></a>00072 
<a name="l00074"></a>00074 
<a name="l00079"></a>00079         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#e71413d96c465b3817f1a3e38f172991" title="Specifies if the series is stacked with other bar series.">SetStacked</a>(<span class="keywordtype">bool</span> bStacked);
<a name="l00081"></a>00081         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_bar_serie.html#4471f2073992b01919342a128b9ffbbe" title="Returns true if the series is stacked.">IsStacked</a>();
<a name="l00082"></a>00082 
<a name="l00084"></a>00084         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#97475ad09ac06af0d9b0a719eaa4cc9a" title="Specifies if a gradient is applied to the bars.">ShowGradient</a>(<span class="keywordtype">bool</span> bShow);
<a name="l00086"></a>00086 
<a name="l00093"></a>00093         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#64f4107f6c697c104a09ff53e3b1d424" title="Sets the gradient style.">SetGradient</a>(COLORREF GradientColor, EGradientType GradientType);
<a name="l00094"></a>00094 
<a name="l00096"></a><a class="code" href="class_c_chart_bar_serie.html#9f45f9eb57c9e5ece67adac71b4fffe1">00096</a>         <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#9f45f9eb57c9e5ece67adac71b4fffe1" title="Static function used to specify the space (in pixels) between series of the same...">SetInterSpace</a>(<span class="keywordtype">int</span> Space)    { m_iInterSpace = Space; }
<a name="l00098"></a><a class="code" href="class_c_chart_bar_serie.html#a127aeb7d339f6ea056573b37e9c6998">00098</a>         <span class="keyword">static</span> <span class="keywordtype">int</span>  <a class="code" href="class_c_chart_bar_serie.html#a127aeb7d339f6ea056573b37e9c6998" title="Static function returning the space between series of the same group.">GetInterSpace</a>()                             { <span class="keywordflow">return</span> m_iInterSpace;  }
<a name="l00099"></a>00099 
<a name="l00101"></a>00101 
<a name="l00110"></a><a class="code" href="class_c_chart_bar_serie.html#03c8e2170ffe73224bb2434613e484e5">00110</a>         <span class="keywordtype">void</span> <a class="code" href="class_c_chart_bar_serie.html#03c8e2170ffe73224bb2434613e484e5" title="Specifies a base line for the bars.">SetBaseLine</a>(<span class="keywordtype">bool</span> bAutomatic, <span class="keywordtype">double</span> dBaseLine)
<a name="l00111"></a>00111         {
<a name="l00112"></a>00112                 m_bAutoBaseLine = bAutomatic;
<a name="l00113"></a>00113                 m_dBaseLine = dBaseLine;
<a name="l00114"></a>00114         }
<a name="l00115"></a>00115 
<a name="l00117"></a>00117 
<a name="l00127"></a>00127         <span class="keywordtype">bool</span> <a class="code" href="class_c_chart_bar_serie.html#49c4128340700712f2be11449d59cfee" title="Check whether a screen point is on the series.">IsPointOnSerie</a>(<span class="keyword">const</span> CPoint&amp; screenPoint, <span class="keywordtype">unsigned</span>&amp; uIndex) <span class="keyword">const</span>;
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 <span class="keyword">private</span>:
<a name="l00130"></a>00130         <span class="keyword">typedef</span> std::list&lt;CChartBarSerie*&gt; TBarSeriesList;
<a name="l00131"></a>00131 
<a name="l00133"></a>00133 
<a name="l00140"></a>00140     <span class="keywordtype">void</span> DrawLegend(CDC* pDC, <span class="keyword">const</span> CRect&amp; rectBitmap) <span class="keyword">const</span>;
<a name="l00141"></a>00141 
<a name="l00143"></a>00143 
<a name="l00150"></a>00150         <span class="keywordtype">void</span> Draw(CDC* pDC);
<a name="l00152"></a>00152 
<a name="l00157"></a>00157         <span class="keywordtype">void</span> DrawAll(CDC *pDC);
<a name="l00158"></a>00158 
<a name="l00159"></a>00159         <span class="keywordtype">void</span> DrawBar(CDC* pDC, CBrush* pFillBrush, CBrush* pBorderBrush, 
<a name="l00160"></a>00160                                  CRect BarRect);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162         <span class="comment">// Retrieves the offset of the serie along the minor axis (horizontal</span>
<a name="l00163"></a>00163         <span class="comment">// axis for vertical bars). This offset is based on series with the</span>
<a name="l00164"></a>00164         <span class="comment">// same group Id.</span>
<a name="l00165"></a>00165         <span class="keywordtype">int</span> GetMinorOffset() <span class="keyword">const</span>;
<a name="l00166"></a>00166         CRect GetBarRectangle(<span class="keywordtype">unsigned</span> uPointIndex, <span class="keywordtype">int</span> minorOffset) <span class="keyword">const</span>;
<a name="l00167"></a>00167 
<a name="l00168"></a>00168         <span class="keywordtype">void</span> RefreshStackedCache() <span class="keyword">const</span>;
<a name="l00169"></a>00169 
<a name="l00170"></a>00170 
<a name="l00172"></a>00172         <span class="keyword">static</span> <span class="keywordtype">int</span> m_iInterSpace;       
<a name="l00174"></a>00174         <span class="keyword">static</span> TBarSeriesList m_lstBarSeries;
<a name="l00175"></a>00175         
<a name="l00177"></a>00177         <span class="keywordtype">bool</span> m_bHorizontal;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         <span class="comment">// The base line specifies the position (in terms of the value</span>
<a name="l00180"></a>00180         <span class="comment">// axis) where the bars start from. If m_bAutoBaseLine is true</span>
<a name="l00181"></a>00181         <span class="comment">// they start from the axis position.</span>
<a name="l00182"></a>00182         <span class="keywordtype">double</span> m_dBaseLine;
<a name="l00183"></a>00183         <span class="keywordtype">bool</span> m_bAutoBaseLine;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185         <span class="comment">// Specifies to which group this series belongs to. Series in the same group are</span>
<a name="l00186"></a>00186         <span class="comment">// 'stacked' next to each other.</span>
<a name="l00187"></a>00187         <span class="keywordtype">unsigned</span> m_uGroupId;            
<a name="l00188"></a>00188 
<a name="l00189"></a>00189         <span class="keywordtype">int</span> m_iBarWidth;
<a name="l00190"></a>00190         <span class="keywordtype">int</span> m_iBorderWidth;
<a name="l00191"></a>00191         COLORREF m_BorderColor;
<a name="l00192"></a>00192 
<a name="l00193"></a>00193         <span class="keywordtype">bool</span> m_bGradient;
<a name="l00194"></a>00194         COLORREF m_GradientColor;
<a name="l00195"></a>00195         EGradientType m_GradientType;
<a name="l00196"></a>00196 
<a name="l00197"></a>00197         <span class="comment">// Specifies if the bar series has to be stacked with other bar </span>
<a name="l00198"></a>00198         <span class="comment">// series with the same group Id</span>
<a name="l00199"></a>00199         <span class="keywordtype">bool</span> m_bStacked;
<a name="l00200"></a>00200 
<a name="l00201"></a>00201         <span class="comment">// Cache of the stacked series with the same group Id as this series.</span>
<a name="l00202"></a>00202         <span class="keyword">mutable</span> TBarSeriesList m_lstStackedSeries;
<a name="l00203"></a>00203 };
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Jan 17 13:33:09 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