ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Barchart resizing issue
Posted by Marco D'Aurelio on Mar-14-2018 23:40
Attachments:
Hello,

I am using BarChart to make a plot in which a rectangle show if the value of a parameter is above or below a threshold, and the value of the parameter is also written. I use a Textbox to insert the value in the plot, highlighted in orange for debugging purpose.

My problem is that I am not able to keep the value alinged to the rectangles, especially when I resize the plot horizontally, although I explicitly set the value of the bar width and bar gap fixed. This lack of alignment repeats periodically with stretching: unalignment reaches its max, then it reduces again.
From my settings, the bar gap and width should never change, but they do.

I attach a sample of code and the pictures.

"
static inline void SetBarWidth(BaseBoxLayer &aLayer, int iWidth, int iGap) {
    if (iWidth >= 0) {
        aLayer.setDataWidth(iWidth);
        if (iGap != 0) {
            aLayer.setDataGap(double(iGap) / double(iWidth));
        }
        else {
            aLayer.setDataGap(Chart::TouchBar);
        }
    }
}

// removed for brevity

BaseBoxLayer *pLayer2 = aChart.addBoxLayer(*lstDoubleArray[4], *lstDoubleArray[3],
                                            CGearboxColors::BearingDamageToColor(bdNotOk)));
SetBarWidth(*pLayer2, m_Data.GetBarWidth(), m_Data.GetBarGap());

const int iY = m_rcPlotArea.GetTop() + m_rcPlotArea.GetHeight() / 2;
const int iBarWidth = m_Data.GetBarWidth() + m_Data.GetBarGap();

for (size_t j = 0; it != Item.GetData().end(); it++, j++) {
    TextBox* dataLabel = aChart.addText(
        m_rcPlotArea.GetLeft() + iBarWidth * j + m_Data.GetBarGap()/2,
        iY,
        wxString::Format("%.1lf", it->X).mb_str(wxConvUTF8),
        m_strFontFileName.mb_str(wxConvUTF8),
        m_iFontSize, m_iFontColor,
        Chart::Center
    );
    dataLabel->setWidth(m_Data.GetBarWidth());
    dataLabel->setBackground(0x00FF6347);
}

"


Thank you in advance,

Marco D'Aurelio
Plot not resized.PNG
Plot resized - max unalignment.PNG
PLot resized - re-alignment..PNG

  Re: Barchart resizing issue
Posted by Marco D'Aurelio on Mar-15-2018 18:45
Hello everyone,

I solved my issue with a "trick" not involving textbox. I draw a barchart layer, with transparent background and border, and I add custom labels on it using addCustomDataLabel(). It's not as clean as the textbox, but it works.

The issue on TextBox remains open.

Thank you anyway,

Marco D'Aurelio

  Re: Barchart resizing issue
Posted by Peter Kwan on Mar-15-2018 21:49
Hi Marco,

The issue of the TextBox is because the setDataWidth and setDataGap cannot be used at the same time. If you use one of them, the other one will be ignored.

For example, consider a plot area 800 pixels wide, with 10 bars. Each "bar slot" (that is, the bar_width + the bar_gap) must be 80 pixels. If the data width is 60 pixels, then the gap must be 20 pixels. You do not need to set the gap as there is only one possible value. Similar, if you set the gap, then the bar width only has one possible value and there is no need to set it.

So in your case the "const int iBarWidth = m_Data.GetBarWidth() + m_Data.GetBarGap();" is not the correct "bar slot" width, as either m_Data.GetBarWidth() or m_Data.GetBarGap() is ignored (and therefore does not reflect the actual value).

The solution I think of is to add a transparent scatter layer with the data point at the "No Match" position, and then add labels using addCustomDataLabel, where the label is center aligned to the scatter point. But then your method of using a bar layer is equally good.

Actually, it looks like you already have a transparent bar layer there. (How are the vertical grey lines that run from top to bottom created?) If there is already a transparent bar layer, you can just add the label to the transparent bar layer using center alignment.

Regards
Peter Kwan