|
[MFC] How to set xAxis labels properly. |
Posted by Kaiden on Jul-16-2013 15:45 |
|
Hello Peter,
I really need your help. I am reading in a csv file and then drawing a plot.
for the xaxis labels, i put the "label" in an array.
1. When I first draw the plot, its good. But as I zoom in, some kind of scale shows up on
the xAxis. How can I get rid of the scaling part?
2. First picture has 8 labels. but after few zoom in and out, I can only see few of them.
The rest are turned in to numbers.(first label as 0 and 1 the next and so on..)
Any suggestions??
I have few more questions on other things, but it would be better off asking in a different
question. I will ask again.^^;
Below are the codes, Please help me Pete.
-Best Regards,
Kaiden.
m_pChart = new XYChart(800, 600, 0xf0f0f0, 0xaaaaaa);
m_pChart->setPlotArea(55, 90, m_pChart->getWidth() - 90, m_pChart-
>getHeight() - 160, 0xf0f0f0, -1, Chart::Transparent, 0x7F7F7F, 0x7F7F7F);
m_pChart->addLegend(30, 20, false, "arialbd.ttf", 9)-
>setBackground(Chart::Transparent);
m_pChart->setClipping();
m_pChart->addTitle(m_graphTitle, "timesbi.ttf", 18);
m_pChart->xAxis()->setLabelStyle("arialbd.ttf", 7, 0x008000)-
>setFontAngle(45);
m_pChart->xAxis()->setLabels(StringArray(m_labels, arrFoundSize));
m_pChart->getLegend()->setLineStyleKey();
m_pChart->getLegend()->setFontSize(8);
m_pChart->xAxis()->setColors(Chart::Transparent);
m_pChart->yAxis()->setColors(Chart::Transparent);
m_pChart->xAxis()->setLabelStep(1);
vector< LineLayer* > vecLineLayer;
for(int iLayerIdx = 0; iLayerIdx != m_pDoc->iTotalRowCount; iLayerIdx++)
{
LineLayer* layer = m_pChart->addLineLayer();
layer->setLineWidth(2);
layer->setFastLineMode();
vecLineLayer.push_back(layer);
}
for(int i=0; i<m_pDoc->iTotalRowCount; i++)
{
vecLineLayer[i]->addDataSet(DoubleArray(dTitle[i], arrFoundSize),
m_aryTotalCountColor.GetAt(i));
}
m_chartView.syncLinearAxisWithViewPort("x", m_pChart->xAxis());
m_chartView.syncLinearAxisWithViewPort("y", m_pChart->yAxis());
m_chartView.setScrollDirection(Chart::DirectionHorizontalVertical);
m_chartView.setZoomDirection(Chart::DirectionHorizontalVertical);
m_chartView.setChart(m_pChart); |
Re: [MFC] How to set xAxis labels properly. |
Posted by Kaiden on Jul-16-2013 15:47 |
|
picture wasn't attached. |
Re: [MFC] How to set xAxis labels properly. |
Posted by Kaiden on Jul-16-2013 15:47 |
|
picture again.
|
Re: [MFC] How to set xAxis labels properly. |
Posted by Peter Kwan on Jul-17-2013 05:43 |
|
Hi Kaiden,
If your x-axis labels are really numeric or date/time values representing the x-position of the data points, instead of using Axis.setLabels, you may consider to use Layer.setXData to specify the x-coordinates of the data points. In this case, the syncLinearAxisWithViewPort should work as in the sample code.
If Axis.setLabels is used, ChartDirector will treat the labels as "names" to be put on the x-axis. The labels themselves will have no meaning to ChartDirector and are just for human reading. This type of axis is not exactly the same as a "linear axis", and so the syncLinearAxisWithViewPort cannot be used. If you use syncLinearAxisWithViewPort for the x-axis, ChartDirector will automatically put the numeric labels on the x-axis (just like it automatically puts numeric labels on the y-axis), and this will interfere with your own labels.
For a label based x-axis, you may consider the following code instead of using syncLinearAxisWithViewPort/setLabels/setLabelStep:
// Set the visible x-axis label range
viewer->setFullRange("x", 0, no_of_labels - 1);
double startLabelIndex = viewer->getValueAtViewPort("x", viewer->getViewPortLeft());
double endLabelIndex = viewer->getValueAtViewPort("x", viewer->getViewPortLeft() + viewer->getViewPortWidth());
c->xAxis()->setLinearScale(startLabelIndex, endLabelIndex, Chart::NoValue);
// Add the labels with the range
for (int i = (int)ceil(startLabelIndex); i <= endLabelIndex; ++i)
c->xAxis()->addLabel(i, myLabels[i]);
Hope this can help.
Regards
Peter Kwan |
Re: [MFC] How to set xAxis labels properly. |
Posted by Kaiden on Jul-22-2013 14:59 |
|
Hi Peter!
This works perfectly!!
Thanks man. I really do appreciated it!
Best Regards
Kiaden. |
|