Well, not at the moment, mainly because I have little time to work on the library, but it is a good idea, and I'll add it to the wish list.
In any case, it should not be difficult to implement a new layer to plot bar charts: it is a matter to derive a new class from mpLayer and to override the Plot method to draw rectangles instead of lines.
CD-RON77
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some example code for the Plot function of a bar based layer. Note that this code uses some other data particular to my derived classes so it will not work as is with mathplot you will need to modify it to do this but it gives an idea of what is needed.
{
// Set the pen
dc.SetPen( m_pen);
// Plot all points
int numPoints = (int)(points.size() - m_firstValidPoint);
// Calculate the X coord of the left and right
// border of the plot window. This will allow
// us to only plot points that fall in this region
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
double leftX = w.p2x(startPx);
double rightX = w.p2x(endPx);
wxCoord ptX, ptY;
// Create pen for points with colour
//wxPen diffPen = m_pen;
wxBrush plotBrush;
plotBrush.SetStyle(wxSOLID);
// Caclulate width of bar to draw
int barWidth = 0.8 * w.GetScaleX();
if (barWidth == 0)
barWidth = 1;
// Get the zero y position
wxCoord zeroY = w.y2p(0);
for (int counter = m_firstValidPoint; counter < numPoints; counter++)
{
// Check if in range
if (points[counter].xCoord <= rightX)
{
if (points[counter].xCoord >= leftX)
{
ptX = w.x2p(points[counter].xCoord);
ptY = w.y2p(points[counter].yCoord);
// Set brush (fill) colour
if (points[counter].colour != wxNullColour)
{
plotBrush.SetColour(points[counter].colour);
}
else
{
plotBrush.SetColour(m_pen.GetColour());
}
// Set brush
dc.SetBrush(plotBrush);
// Draw line
dc.DrawRectangle(ptX - (barWidth/2), ptY, barWidth, zeroY - ptY);
}
}
}
// Reset brush to normal
dc.SetBrush(wxNullBrush);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, There's already bar -charts implemented to wxMathPlot: http://code.google.com/p/gppanel/
gpPanel contains several other new feature also which might be useful for you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I like this library. Is there any plan to add bar charts in wxMathPlot?
Well, not at the moment, mainly because I have little time to work on the library, but it is a good idea, and I'll add it to the wish list.
In any case, it should not be difficult to implement a new layer to plot bar charts: it is a matter to derive a new class from mpLayer and to override the Plot method to draw rectangles instead of lines.
CD-RON77
Some example code for the Plot function of a bar based layer. Note that this code uses some other data particular to my derived classes so it will not work as is with mathplot you will need to modify it to do this but it gives an idea of what is needed.
{
// Set the pen
dc.SetPen( m_pen);
// Plot all points
int numPoints = (int)(points.size() - m_firstValidPoint);
// Calculate the X coord of the left and right
// border of the plot window. This will allow
// us to only plot points that fall in this region
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
double leftX = w.p2x(startPx);
double rightX = w.p2x(endPx);
wxCoord ptX, ptY;
// Create pen for points with colour
//wxPen diffPen = m_pen;
wxBrush plotBrush;
plotBrush.SetStyle(wxSOLID);
// Caclulate width of bar to draw
int barWidth = 0.8 * w.GetScaleX();
if (barWidth == 0)
barWidth = 1;
// Get the zero y position
wxCoord zeroY = w.y2p(0);
for (int counter = m_firstValidPoint; counter < numPoints; counter++)
{
// Check if in range
if (points[counter].xCoord <= rightX)
{
if (points[counter].xCoord >= leftX)
{
ptX = w.x2p(points[counter].xCoord);
ptY = w.y2p(points[counter].yCoord);
// Set brush (fill) colour
if (points[counter].colour != wxNullColour)
{
plotBrush.SetColour(points[counter].colour);
}
else
{
plotBrush.SetColour(m_pen.GetColour());
}
// Set brush
dc.SetBrush(plotBrush);
// Draw line
dc.DrawRectangle(ptX - (barWidth/2), ptY, barWidth, zeroY - ptY);
}
}
}
// Reset brush to normal
dc.SetBrush(wxNullBrush);
}
Hi,
When i am going to click mouse left on a mpwindow it needs to find a particular layer.Can u given me a Suggestion.
Thank You,
EN-0028
Hi, There's already bar -charts implemented to wxMathPlot:
http://code.google.com/p/gppanel/
gpPanel contains several other new feature also which might be useful for you.