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

Message ListMessage List     Post MessagePost Message

  VC++ 6, no XYChart on CDC
Posted by S. K?nig on Jul-19-2013 14:20
Hallo,
I'm testing some chartcontrols in our c++ application.
The following code does not show the chart on the form.

double data[] = {85, 156, 179.5, 211, 123};
const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};
XYChart *c = new XYChart(250, 250);
c->setPlotArea(30, 20, 200, 200);
c->addBarLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))));
c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))));

CPaintDC pDC(this);
CBitmap bitmap;
CDC dcMem;

MemBlock bmp = c->makeChart(Chart::BMP);

LPBITMAPINFO header = (LPBITMAPINFO)(bmp.data + 14);
LPBYTE bitData = (LPBYTE)(bmp.data) + ((LPBITMAPFILEHEADER)(bmp.data))->bfOffBits;

int isbitmapvalid = bitmap.CreateBitmap(250, 250, 1, 8, bitData);

dcMem.CreateCompatibleDC(&pDC);
dcMem.SelectObject(&bitmap);
pDC.BitBlt(100,100,250,250,&dcMem,0,0,SRCCOPY);

delete c;

  Re: VC++ 6, no XYChart on CDC
Posted by S. K?nig on Jul-19-2013 19:43
Hallo,
after some research, i think it is a Color-Palette problem.
Your chart in MemBlock is a 8 bit or 24 bit bitmap. This bitmap cannot be displayed in our 32 bit environment.

  Re: VC++ 6, no XYChart on CDC
Posted by Peter Kwan on Jul-20-2013 01:11
Hi S. K?nig,

The output of makeChart(Chart::BMP) is a device independent bitmap. It is not an array of pixels ordered from left to right, top to bottom. (As according to the BMP/DIB standard, the ordering is different, and the actual pixels can be encoded in various ways.)

The correct method to draw to a device context is to use StretchDIBits. For example:

MemBlock m = c->makeChart(Chart::BMP);

::StretchDIBits ( hDC,
     100, 100, 250, 250,
     0, 0, 250, 250,
     (LPBYTE)(m.data) + ((LPBITMAPFILEHEADER)(m.data))->bfOffBits,
     (LPBITMAPINFO)(m.data + 14),
     DIB_RGB_COLORS,
     SRCCOPY);

Hope this can help.

Regards
Peter Kwan