|
Why addMark line dost not fit exact y-position? |
Posted by Shenggang Zhang on Apr-12-2021 17:58 |
|
Dear support manager,
The problem is when calling addMark on yAxis of financechart, the mark line was not at exact position.
The attachment png file is a sample. In the picture, I think 6321.00 should be in the middle of [6315.80, 6326.20], but it fails.
Very strange, could you tell me why?
Thanks a lot!
Shenggang, 4/12/2021
|
Re: Why addMark line dost not fit exact y-position? |
Posted by Peter Kwan on Apr-13-2021 18:59 |
|
Hi Shenggang,
Would you mind to inform me which programming langauge edition of ChartDirector you are using and the framework you are using? (For example, C++/MFC, C#/Windows Forms, C#/ASP.NET, PHP/Web, etc).
For your case, the labels on the right y-axis jumps at 5.2 intervals. It is probably that the axis scale is configured with your code, and not automatically determined by ChartDirector. The left y-axis seems to be synchronized with the right y-axis.
I tried with the following code (in C#):
XYChart m = c.addMainChart(600);
m.yAxis().setLinearScale(6206.6, 6331.4, 5.2);
m.yAxis().addMark(6321.0, 0xff0000);
m.yAxis2().syncAxis(m.yAxis(), 100.0/6321.0, -100);
m.yAxis2().setLabelFormat("{value|2}%");
The above code works normally in my case. The 6321.0 is at the correct position.
Is it possible to create an example (such as by modifying the "Finance Chart (1)" sample code) to help me reproduce the problem?
Regards
Peter Kwan |
Re: Why addMark line dost not fit exact y-position? |
Posted by Shenggang Zhang on Apr-14-2021 10:16 |
|
Hi Peter,
Very appreciate your reply. Here is my c++ code snippet.
XYChart* c = m.addMainChart(mainHeight);
c->addText(50, 21, PrivGetKLineTypeStr(Type_K_Tick).c_str(), "simsun.ttc", 10, 0x00c0c0);
c->getPlotArea()->setBackground(cBackColor, -1, cPlotAreaBorderColor);
c->getPlotArea()->setGridColor(c->dashLineColor(cGridColor, Chart::DotLine), c->dashLineColor(cGridColor, Chart::DotLine)/*Chart::Transparent*/, cGridColor, cGridColor);
c->yAxis()->setColors(cPlotAreaBorderColor, 0xc8c8c8, 0xc8c8c8, cPlotAreaBorderColor);
c->xAxis()->setColors(cPlotAreaBorderColor, 0xc8c8c8, 0xc8c8c8, cPlotAreaBorderColor);
c->xAxis()->setTickLength(4);
c->yAxis()->setLinearScale(yAxisData.GetLowPrice(), yAxisData.GetHighPrice(), StringArray(m_yLabels, yAxisData.GetNum()));
std::string sBaseLabel = "<*font=arial.ttf,color=c8c8c8,size=8*>";
sBaseLabel += F2Str(aTick.dPreSettlementPrice);
Mark* pMark = c->yAxis()->addMark(aTick.dPreSettlementPrice, 0x606060, sBaseLabel.c_str(), "arial.ttf");
pMark->setDrawOnTop(false);
pMark->setLineWidth(1);
c->yAxis2()->setColors(cPlotAreaBorderColor, 0xc8c8c8, 0xc8c8c8, cPlotAreaBorderColor);
c->yAxis2()->syncAxis(c->yAxis());
c->yAxis2()->setLinearScale(yAxisData.GetLowPrice(), yAxisData.GetHighPrice(), StringArray(m_y2Labels, yAxisData.GetNum()));
pMark->setValue(aTick.dPreSettlementPrice);
Thanks a lot!
Shenggang
2021/4/14 |
Re: Why addMark line dost not fit exact y-position? |
Posted by Peter Kwan on Apr-14-2021 16:25 |
|
Hi Shenggang.
I see that your y-axis is configured as:
c->yAxis()->setLinearScale(yAxisData.GetLowPrice(), yAxisData.GetHighPrice(), StringArray(m_yLabels, yAxisData.GetNum()));
Just by looking at the code, we do not know whether the m_yLabels reflect the y-axis values or not. In your chart, the first and last m_yLabels are "6206.60" and "6331.40". However you verify that yAxisData.GetLowPrice() and yAxisData.GetHighPrice() are really 6206.60 and 6331.40?
For testing, please try to modify your code to:
c->yAxis()->setLinearScale(yAxisData.GetLowPrice(), yAxisData.GetHighPrice(), 20);
With the above code, the labels are generated by ChartDirector and it should match the actual scale. Please check if the mark line are then consistent with the labels.
Regards
Peter Kwan |
Re: Why addMark line dost not fit exact y-position? |
Posted by Shenggang Zhang on Apr-15-2021 10:08 |
|
Hi Peter,
Very appreciate your reply. You are right. When I add "//correction" line to adjust dHighPrice, it works now!
double d = dLowPrice;
int nLabelsNum = static_cast<int>((dHighPrice - dLowPrice) / dStep + 0.5) + 1;
double* pLabels = new double[nLabelsNum];
for (int n = 0; n < nLabelsNum; n++)
{
pLabels[n] = d;
d += dStep;
}
dHighPrice = pLabels[nLabelsNum-1]; //correction
//output
yAxisData.pLabels = pLabels;
yAxisData.nNum = nLabelsNum;
yAxisData.dLowPrice = dLowPrice;
yAxisData.dHighPrice = dHighPrice;
The problem is solved. Thank you very much!
Regards
Shenggang
2021/4/15 |
|