I want to begin with a special thanks to CodeProject for providing so many useful samples, and thanks especially to the author of this article: Customizing the .NET Panel control.
If you know about the EBP products, then you'll remember their main board with a simple but cool isometric 3D chart. So, let's do the same here. All the code has been verified under Microsoft FxCop 1.35.
I'm not very comfortable in writing articles even in French, so English isn't better ;p.
Using the code
Let's see the creation code:
this.m_chartSample1 = new Nolme.WinForms.Chart(this.components);
this.m_chartSample1.BackColor = System.Drawing.Color.Silver;
this.m_chartSample1.BottomMargin = 20;
this.m_chartSample1.ColumnFont = new System.Drawing.Font(
"Arial", 8F, System.Drawing.FontStyle.Italic);
this.m_chartSample1.ColumnTitleFont = new System.Drawing.Font(
"Arial", 10F, System.Drawing.FontStyle.Underline);
this.m_chartSample1.Curvature = 15;
this.m_chartSample1.DeltaDepth = 10;
this.m_chartSample1.DisplayHiddenSides = true;
this.m_chartSample1.DisplayTextOnColumns = true;
this.m_chartSample1.LeftMargin = 50;
this.m_chartSample1.LegendFont = new System.Drawing.Font(
"Arial", 11F, System.Drawing.FontStyle.Bold);
this.m_chartSample1.Location = new System.Drawing.Point(8, 8);
this.m_chartSample1.MainTitle = "Main title";
this.m_chartSample1.MainTitleFont = new System.Drawing.Font(
this.m_chartSample1.MarginBetweenColumn = 20;
this.m_chartSample1.Name = "m_chartSample1";
this.m_chartSample1.RightMargin = 20;
this.m_chartSample1.Size = new System.Drawing.Size(456, 304);
this.m_chartSample1.TabIndex = 4;
this.m_chartSample1.TopMargin = 20;
this.m_chartSample1.VerticalAxisMaxValue = 10000;
this.m_chartSample1.VerticalAxisStep = 1000;
Adding a column to the chart is done with the following code:
ChartColumn column1 =
m_chartSample1.AddColumn (1500, 210, 0, 500);
Each number represents a sub-value in the new column. You can pass an integer array if you have more values.
You can set the column title like this:
column1.Title = "January";
Other attributes like the margins, main title, etc., can be changed.
There were two choices on the legend of the graph. We could either integrate the legend into the current panel, or make another independent object. The main intention is to provide a centralized unique legend if multiple charts are used on the same page.
To summarize, a
Chart (derived from
CustomPanel) contains one or more
ChartLegend is composed of
CharLegendItems. There are as many
CharLegendItems as sub-values in a
Points of interest
I've tried to make the code as simple as possible so that anyone can upgrade it.
- Thanks timbits214, changes have been done.
- So, I've added a new mode for 'real time' rendering.
- Chart.cs has a new method,
ShiftLeft, to shift columns from one step to the left.
- With these changes,
ChartColumn integrates a default constructor and
- The new version contains a new rendering mode: 3D with gradient.
- Bug fixed: Left grid text starting at 0.
- Bug fixed: Vertical axis auto-adjusts when min and max don't have the same digit numbers (100 and 1000, for example).
- Bug fixed: Border drawings and optimization.
- Bug fixed: Label on the column with negative values.
- New function:
DisplayBorders in ChartColumn.cs.
- Some changes have been made in the function parameters list to support gradient drawing mode.
- New version contains a new rendering mode. See the
- Associated to this new mode,
ChartCumulativeMode enum can define where a label on the column is placed.
- Some changes have been made in the function parameters list.
- Negative values are now managed.
- The function
AdjustVerticalAxis has been reviewed.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.