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

Message ListMessage List     Post MessagePost Message

  need irregular spacing between x axis grid
Posted by vas on Feb-05-2014 18:17
Attachments:
hi,
    i started working with chart director, i got stuck with a problem. in x axis i am using
date as labels. i  need irregular space between grids based on dates.

i am posting my code below and i am attaching a screenshot too.

double data0[] =
{99.6,99.5,99.4,99.2,99,98.9,98.8,98.4,98.2,98.1,97.9,97.7,97.5,97.3,97.1,96.8,96.6,96.
4,96.2,96.1,95.8,95.6,95.5};


const char *labels[] = {"2 Months", "6 Months", "10 Months", "1 year", "2 Years", "4
years", "5 years", "6 Years", "10 years"};

double datax[] =
{Chart::chartTime(2014,3,1),Chart::chartTime(2014,7,1),Chart::chartTime(2014,11,1),Ch
art::chartTime(2015,1,1),Chart::chartTime(2016,1,1),Chart::chartTime(2018,1,1),Chart::
chartTime(2019,1,1),
              Chart::chartTime(2020,1,1),Chart::chartTime(2024,1,1)};

double d1 = Chart::chartTime(2014,1,1);
double d2 = Chart::chartTime(2024,1,1);

XYChart *m_pXYChart;

m_pXYChart = new XYChart(rRect.Width() - 10, rRect.Height()-10, /*0xffdddd*/0xffffff,
0x000000, 1);



m_pXYChart->setPlotArea(55, 28, rRect.Width() - 100, rRect.Height()-95, 0xffffff, -1, -1,
0xcccccc, 0xcccccc);


m_pXYChart->addLegend(55, 32, false, "arialbd.ttf", 9)-
>setBackground(Chart::Transparent);



m_pXYChart->xAxis()->setWidth(2);
m_pXYChart->yAxis()->setWidth(2);


m_pXYChart->xAxis()->setDateScale(d1,d2,StringArray(labels, (int)(sizeof(labels) /
sizeof(labels[0]))));


SplineLayer *layer = m_pXYChart->addSplineLayer();


layer->setLineWidth(2);


layer->addDataSet(DoubleArray(data0, (int)(sizeof(data0) / sizeof(data0[0]))),
        0x982810)->setDataSymbol(Chart::DiamondSymbol,9, 0xf040f0);


layer->setXData(d1,d2);


ChartViewer.setChart(m_pXYChart);



in the screen shot u can see that in x axis the grids are evenly spaced.
for example, the first label is 2months and the second is 6months, the difference is 4
months and the difference between 3rd and 4th label is 2months but it is drawing with
same grid space . i want to show that differnce in grid by irregular space..
Untitled.jpg

  Re: need irregular spacing between x axis grid
Posted by Peter Kwan on Feb-06-2014 01:41
Hi Vas,

Instead of using:

m_pXYChart->xAxis()->setDateScale(d1,d2,StringArray(labels, (int)(sizeof(labels) /
sizeof(labels[0]))));

please use:

//no label
m_pXYChart->xAxis()->setDateScale(d1,d2,StringArray());

// add labels[i] at datax[i]
for (int i = 0; i < (int)(sizeof(labels) / sizeof(labels[0])); ++i);
    m_pXYChart->xAxis()->addLabel(datax[i], labels[i]);

Hope this can help.

Regards
Peter Kwan

  Re: need irregular spacing between x axis grid
Posted by vas on Feb-06-2014 13:28
hi Peter,
          I used the code what u gave, i got exactly what i need.. thank u..


Regards,
vas