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

Message ListMessage List     Post MessagePost Message

  Data Table
Posted by Ian Hammond on Dec-07-2017 22:14
Hi,
I am new to ChartDirector. I have drawn a simple wind rose and wish to display a data table alongside said plot. I have added data to a table but it does not appear alongside my rose. I am trying to work out how to draw the table from the examples but I'm missing something. I would appreciate any advice, many thanks.

  Re: Data Table
Posted by Peter Kwan on Dec-08-2017 00:44
Hi Ian,

I can write an example for you. Would you mind to inform me which programming language you are using? (ChartDirector supports many programming languages.)

Regards
Peter Kwan

  Re: Data Table
Posted by Ian Hammond on Dec-08-2017 17:49
Many thanks for your response. I am currently using C++.

  Re: Data Table
Posted by Peter Kwan on Dec-08-2017 23:53
Attachments:
Hi Ian,

Below please find an example chart and the code that generate the chart.

Hope this can help.

Regards
Peter Kwan
rose.png
rose.cpp
#include "chartdir.h"
#include <stdio.h>

int main(int argc, char *argv[])
{
    // Data for the chart
    double data[] = {9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2,
        5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5};
    double angles[] = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240,
        255, 270, 285, 300, 315, 330, 345};

    // Create a PolarChart object of size 460 x 460 pixels, with a silver background and a 1 pixel
    // 3D border
    PolarChart *c = new PolarChart(680, 460);

    // Set plot area center at (230, 240) with radius 180 pixels and white background
    c->setPlotArea(230, 240, 180, 0xffffff);

    // Set the grid style to circular grid
    c->setGridStyle(false);

    // Set angular axis as 0 - 360, with a spoke every 30 units
    c->angularAxis()->setLinearScale(0, 360, 30);

    // Add sectors to the chart as sector zones
    for(int i = 0; i < (int)(sizeof(data) / sizeof(data[0])); ++i) {
        c->angularAxis()->addZone(angles[i], angles[i] + 15, 0, data[i], 0x33ff33, 0x008000);
    }

    // Add an Transparent invisible layer to ensure the axis is auto-scaled using the data
    c->addLineLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), Chart::Transparent);

	int rowCount = (int)(sizeof(data) / sizeof(data[0]));
	CDMLTable *t = c->addTable(500, 50, Chart::TopLeft, 2, rowCount + 1);
	
	// Set column width
	t->getColStyle(0)->setWidth(75);
	t->getColStyle(1)->setWidth(75);

	// The first row is the header
	t->setText(0, 0, "Angle");
	t->setText(1, 0, "Value");
	TextBox *headerStyle = t->getRowStyle(0);
	headerStyle->setFontStyle("arialbd.ttf");
	headerStyle->setFontColor(0xffffff);
	headerStyle->setBackground(0x444444);

	// The other rows are the data
	for (int i = 0; i < rowCount; ++i)
	{
		char buffer[1024];

		sprintf(buffer, "%g", angles[i]);
		t->setText(0, i + 1, buffer);

		sprintf(buffer, "%.2f", data[i]);
		t->setText(1, i + 1, buffer);
	}

	// Output the chart
    c->makeChart("rose.png");

    //free up resources
    delete c;
    return 0;
}


  Re: Data Table
Posted by Ian Hammond on Dec-10-2017 19:18
Hi Peter,

Many thanks for your example, its just what I need.

Kind Regards