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

Message ListMessage List     Post MessagePost Message

  Problem with setDateScale and zooming.
Posted by WNKR10 on Oct-10-2013 16:22
Hi, im using MFC and have modified simplezoomandscroll. When i press a button i get new StartTime and EndTime and call updateViewPort(true, true) and i set them with setDateScale() in drawChart function and the new chart with the new times redraw, but i want to be able to zoomin and out so add
viewer->syncDateAxisWithViewPort("y", m_chart->yAxis());
Then the chart dont redraw with the new StartTime/EndTime and redraw with the old ones so im not able to see the new data, but im able to zoomin/out.. Please help how could i do it?

Regards,
WNKR

void CAnalizArchiveDlg::drawChart(CChartViewer *viewer)
{
///////////////////////////////////////////////////////////////////////////////////////
// Configure overall chart appearance.
///////////////////////////////////////////////////////////////////////////////////////

// Create a XYChart object of size 800 x 280 pixels. Set background color to
// light blue (ccccff), with 1 pixel 3D border effect.
/*XYChart **/ m_chart = new XYChart(1060, 480, 0xccccff, 0x000000, 1);

// Add a title to the chart using 15 points Times Bold Itatic font, with white
// (ffffff) text on a deep blue (000080) background
m_chart->addTitle(TCHARtoUTF8("ЦИКЪЛ НА СТРЕЛБАТА"), "Times New Roman.ttf", 12, 0xffffff
)->setBackground(0x000080);

// Set the plotarea at (140, 55) and of size 640 x 200 pixels. Use alternative
// white/grey background. Enable both horizontal and vertical grids by setting
// their colors to grey (c0c0c0). Set vertical major grid (represents month
// boundaries) 2 pixels in width
m_chart->setPlotArea(140, 55, 900, 200, 0xffffff, 0xeeeeee, Chart::LineColor, 0xc0c0c0, 0xc0c0c0)->setGridWidth(2, 1, 1, 1);
m_chart->setClipping();

// swap the x and y axes to create a horziontal box-whisker chart
m_chart->swapXY();

m_chart->yAxis()->setDateScale(Chart::chartTime(StartTime.GetYear(), StartTime.GetMonth(), StartTime.GetDay(), StartTime.GetHour(), StartTime.GetMinute(),StartTime.GetSecond()), Chart::chartTime(EndTime.GetYear(), EndTime.GetMonth(), EndTime.GetDay(), EndTime.GetHour(), EndTime.GetMinute(), EndTime.GetSecond()));
   //(Chart::chartTime2((int)StartTime.GetTotalSeconds()), //Chart::chartTime2((int)EndTime.GetTotalSeconds()), 0, 0);

// Set multi-style axis label formatting. Month labels are in Arial Bold font in
// "mmm d" format. Intra-month labels just show the day of month and use minor tick
// (by using '-' as first character of format string).
m_chart->yAxis()->setMultiFormat(Chart::AllPassFilter(),
"<*font=arialbd.ttf*>{value|hh:nn:ss}"/*, Chart::StartOfDayFilter(), "-{value|d}"*/);

// Set the y-axis to shown on the top (right + swapXY = top)
m_chart->setYAxisOnRight();

// Here is the problem.. when i comment this i redraw properly with the new start
// and end time, but im not able to zoom, other way im able to zoom, but
// the chart dont display properly
viewer->syncDateAxisWithViewPort("y", m_chart->yAxis());

// Set the x-axis labels
m_chart->xAxis()->setLabels(m_labels);

// Reverse the x-axis scale so that it points downwards.
m_chart->xAxis()->setReverse();

// Set the horizontal ticks and grid lines to be between the bars
m_chart->xAxis()->setTickOffset(0.5);

// Add a green (33ff33) box-whisker layer showing the box only.
// m_chart->addBoxWhiskerLayer(m_startDate, m_endDate, DoubleArray(), DoubleArray(), DoubleArray(), 0x00cc00,
// Chart::SameAsMainColor, Chart::SameAsMainColor);
BoxWhiskerLayer *layer = m_chart->addBoxWhiskerLayer2(DoubleArray(myStartDate, (int)(
sizeof(myStartDate) / sizeof(myStartDate[0]))), DoubleArray(myEndDate, (int)(
sizeof(myEndDate) / sizeof(myEndDate[0]))), DoubleArray(), DoubleArray(),
DoubleArray(), IntArray(myColors, (int)(sizeof(myColors) / sizeof(myColors[0]))));
layer->setXData(DoubleArray(taskNo, (int)(sizeof(taskNo) / sizeof(taskNo[0]))));
layer->setBorderColor(Chart::SameAsMainColor);

LegendBox *LegendBox = m_chart->addLegend2(140, 265, Chart::AutoGrid, "arialbd.ttf", 8);
LegendBox->setWidth(461);
LegendBox->setBackground(0xdddddd);

LegendBox->addKey(no_command, 0xe5e4e2);
LegendBox->addKey(search_com, 0x54c571);
LegendBox->addKey(esscort_target, 0x98afc7);
LegendBox->addKey(kill_target, 0x3bb9ff);
LegendBox->addKey(end_task, 0xb2c248);
LegendBox->addKey(search_sector, 0x3b9c9c);
LegendBox->addKey(end_command_from_staf, 0xcfecec);

// Divide the plot area height ( = 200 in this chart) by the number of tasks to
// get the height of each slot. Use 80% of that as the bar height.
layer->setDataWidth(200 * 4 / 5 / (int)(sizeof(myLabels) / sizeof(myLabels[0])));

///////////////////////////////////////////////////////////////////////////////////////
// Output the chart
///////////////////////////////////////////////////////////////////////////////////////

delete viewer->getChart();
viewer->setChart(m_chart);
}

  Re: Problem with setDateScale and zooming.
Posted by WNKR10 on Oct-10-2013 18:27
I forgot to tell that its Gantt chart and i've declared m_chart in AnalizArchiveDlg.h
XYChart *m_chart;
and i delete it in destructor..

  Re: Problem with setDateScale and zooming.
Posted by WNKR10 on Oct-10-2013 19:07
Well, maybe i found the solution. In function intiChartViewer i call

viewer->SetFullRange("y", Chart::chartTime2(StartTime.GetTotalSeconds()),
                  Chart::chartTime2(EndTime.GetTotalSeconds()));

I will be glad to hear other proposals. :)

  Re: Problem with setDateScale and zooming.
Posted by Peter Kwan on Oct-10-2013 23:59
Hi WNKR10,

When you change the chart in an existing CChartViewer, the CChartViewer will not change the viewport configuration. It is because if the CChartViewer resets the viewport whenever the chart is changed, it would be impossible to support charts that can update (such as realtime charts).

For the viewer->syncDateAxisWithViewPort, it will scale the axis to reflect the visible viewport. For example, if the full range is 180 days, and the viewport is showing 10% of the data, the CChartViewer will scale the axis to show 18 days. To do this, the CChartViewer needs to know the full range. If your code has not called setFullRange, the CChartViewer will auto-detect the full range by auto-scaling the axis when syncDateAxisWithViewPort is called the first time. This full range will be used in subsequent syncDateAxisWithViewPort calls to compute the axis scale. If you change the chart, CChartViewer would still be using the full range it detects in the previous chart to compute the axis scale.

If you would need to reset the full range in the new chart, you may setFullRange to the new full range you want to use, or reset the viewport width to 1 (100% visible), and call setFullRange("y", 0, 0) to cancel the previous full range (as 0 to 0 is not valid as an axis scale, ChartDirector will ignore the 0 to 0 range and auto-detect the full range again using auto-scaling).

Hope this can help.

Regards
Peter Kwan

  Re: Problem with setDateScale and zooming.
Posted by WNKR10 on Oct-11-2013 15:40
Great help as always!
Thanks!