Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Drawing charts with wxWidgets: Part I - Introduction

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
1 May 2013CPOL3 min read 30.4K   4   10
Drawing charts with wxWidgets.

Introduction

I developed wxFreeChart to provide wxWidgets the flexible and comprehensive framework for building charting applications with support of the various chart types, with various data sources, and control of the most visual representation attributes (fonts, axes configuration, titles, background, etc). wxFreeChart is using model-controller-view pattern. It’s design allows to easily integrate various data sources (files, sensors, calculated by application, database, received by network, etc). Data source is abstract, e.g. it’s no sense for framework of how data received. Rendering system enables application developer to make many different chart types with the same approach. Almost every aspect of visual representation can be controlled, this allow you, for example, to make as many axes, as you need, change their colors and fonts, set markers and their appearance, set gradient backgrounds, change legend, chart title and it’s font and color. wxFreeChart is like a set of many building blocks, that developer configure and links them together. Project has wxWidgets license. You can use wxFreeChart in your applications (even commercial) for free.

Supported chart types

wxFreeChart supports the following chart types:

  1. Line XY charts.
  2. Histogram XY charts.
  3. Area XY charts.
  4. Bar charts.
  5. Stacked bar charts.
  6. Layered bar charts.
  7. OHLC bars financial charts.
  8. OHLC candlesticks financial charts.
  9. Bubble charts.
  10. Gantt charts.

Features

  1. Markers.
  2. Crosshair.
  3. Dynamic charts.
  4. Unlimited amount of axes. 
  5. Gradient backgrounds and bars.
  6. Legend.
  7. Bars and candlestick colors can be controlled by various conditions (e.g. indicators, etc).
  8. Zoom and pan for charts.

wxFreeChart design

Main concepts are:

  1. Dataset.
  2. Renderer.
  3. Axis.
  4. Plot.
  5. Chart.
  6. wxChartPanel.

Dataset

Dataset is a data access interface. It's a model in Model-Controller-View pattern. It doesn't hold data by itself, it only defines data interface. There are different implementations (they are described below). You can write your own Dataset implementation, if noone provided classes fits your needs.

Datasets can be following types:

  1. XYDataset. Provides data for charts, based on XY coordinates.
  2. CategoryDataset. For charts with numeric/string information on one axis, and string information on another, and pie plots.
  3. OHLCDataset. For financial quote charts.
  4. XYZDataset. For bubble charts.

Renderer

Renderer is object, that performs data drawing. For one dataset type, can be many renderer, for example: XYDataset can be rendered as lines, histogram or area, OHLCDataset can be drawn as bars or candlesticks.

Renderers can be following types:

  1. XYRenderer. For drawing XY data.
  2. BarRenderer. For drawing bars: normal, stacked, layered.
  3. OHLCRenderer. For drawing financial quote data.
  4. XYZDataset. For drawing XYZ data.

Axis

Axis is an object, that performs data scaling and axis rendering.

  1. NumberAxis. For displaying numeric labels, and scaling numeric data.
  2. CategoryAxis. For string labels.
  3. DateAxis. For date/time labels.
  4. CompDateAxis. Interval axis for date/time labels.

Plot

Plot is an object, that connects axes, datasets, visual objects (markers, crosshairs). It contains title, background, etc.

Chart

Chart is an object, that contains title, plot.

Other objects

  1. Markers.
  2. Area draws.
  3. Legend.
  4. AxisShare.
  5. Multiplot.

Markers

Markers are used to mark data values and/or intervals. Markers are connected with dataset. There are following marker types:

  1. Point marker. Marks single point value.
  2. Line marker. Uses to mark the specified value as line.
  3. Range marker. Used to mark the specified range of values.

Area draws

Area draws are objects, that performs drawing background (plot, chart), bars in bars plots, legend symbols, etc. There two area draw types: fill and gradient.

Legend

Legend draws legend symbols and serie names. It has position within plot, font to draw labels, etc. Legend can be vertical or horizontal.

AxisShare

AxisShare is helper object, that makes it possible to create combined axis plots.

Multiplot

Multiplot is a special kind of plot, that contains many subplots. It's used to 

Summary

In this part of article, i introduced wxFreeChart design. In the next parts i will provide you an example of how to create a simple chart, more detailed explanation for wxFreeChart objects, dataset-renderers configurations for each chart type.

Links

wxFreeChart home page: http://wxcode.sourceforge.net/components/freechart/

License

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


Written By
CEO BitGriff LLC
Russian Federation Russian Federation
My name is Andrey Moskvichev.

I'm a software developer with more than 14 years of programming experience.

I specialize in networking, Unix systems (Linux, FreeBSD), mobile programming, computer graphics, software architecture, reverse engineering, data processing systems, AI, computer vision.

I'm interested in all new cutting edge technologies.

Comments and Discussions

 
PraiseThanks Pin
Member 1510039416-Oct-22 16:09
Member 1510039416-Oct-22 16:09 
QuestionMultiaxis Pin
black_box8-Nov-19 1:35
black_box8-Nov-19 1:35 
QuestionHow can I display data with labels on y-axis and integer values on x-label ? Pin
Member 1261011529-Jun-16 2:49
Member 1261011529-Jun-16 2:49 
QuestionCompile issues Pin
MiguelLM2-May-15 5:12
MiguelLM2-May-15 5:12 
QuestionI am trying to build demo... but failing Pin
Jasin Colegrove14-Mar-15 15:13
Jasin Colegrove14-Mar-15 15:13 
AnswerRe: I am trying to build demo... but failing Pin
Andrey Moskvichev2-Apr-15 2:38
professionalAndrey Moskvichev2-Apr-15 2:38 
QuestionDraggable markers - possible ? Pin
jonne7713-Oct-14 22:12
jonne7713-Oct-14 22:12 
AnswerRe: Draggable markers - possible ? Pin
Andrey Moskvichev14-Oct-14 8:45
professionalAndrey Moskvichev14-Oct-14 8:45 
Questionneed to build wxFreeChart for MFC Pin
sma123#16-Jun-14 15:03
sma123#16-Jun-14 15:03 
Hi Andrey Moskvichev,
I am trying to build this in MFC application with no luck.
Can you plz help me on this?

Regards,
SMA
AnswerRe: need to build wxFreeChart for MFC Pin
Andrey Moskvichev29-Jun-14 23:05
professionalAndrey Moskvichev29-Jun-14 23:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.