Click here to Skip to main content
14,365,441 members

Drawing charts with wxWidgets: Part I - Introduction

Rate this:
5.00 (4 votes)
Please Sign up or sign in to vote.
5.00 (4 votes)
1 May 2013CPOL
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)

Share

About the Author

Andrey Moskvichev
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

 
QuestionMultiaxis Pin
black_box8-Nov-19 2:35
memberblack_box8-Nov-19 2:35 
Hello Andrey,
I trie to use your lib to draw a set of curves at the same math2Dplot objct, the issue is with axis that the curves have different axis and intervals (unities too). How can I add a second y Axis for example or must I overload the axis class i. e. derive a new one supporting multiaxis? Or do you have supported such use case already in your implementation?
I have 3 curves withe same x axis and y1, y2, and y3 my idea is to have some thing like:
.......|---------------------------------------|
y1-|-y2-----------------------------------|-y3
.......|---------------------------------------|
.......|______________X________________________|


thank you in advance
best regards
Ken
QuestionHow can I display data with labels on y-axis and integer values on x-label ? Pin
Member 1261011529-Jun-16 3:49
memberMember 1261011529-Jun-16 3:49 
QuestionCompile issues Pin
MiguelLM2-May-15 6:12
memberMiguelLM2-May-15 6:12 
QuestionI am trying to build demo... but failing Pin
Jasin Colegrove14-Mar-15 16:13
memberJasin Colegrove14-Mar-15 16:13 
AnswerRe: I am trying to build demo... but failing Pin
Andrey Moskvichev2-Apr-15 3:38
professionalAndrey Moskvichev2-Apr-15 3:38 
QuestionDraggable markers - possible ? Pin
jonne7713-Oct-14 23:12
memberjonne7713-Oct-14 23:12 
AnswerRe: Draggable markers - possible ? Pin
Andrey Moskvichev14-Oct-14 9:45
professionalAndrey Moskvichev14-Oct-14 9:45 
Questionneed to build wxFreeChart for MFC Pin
sma123#16-Jun-14 16:03
membersma123#16-Jun-14 16:03 
AnswerRe: need to build wxFreeChart for MFC Pin
Andrey Moskvichev30-Jun-14 0:05
professionalAndrey Moskvichev30-Jun-14 0: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.

Technical Blog
Posted 1 May 2013

Tagged as

Stats

20.9K views
3 bookmarked