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

Message ListMessage List     Post MessagePost Message

  how to fill the xAxis with time lables
Posted by hondodo on Apr-06-2016 12:34
Attachments:
Hi, i add a AreaLayer to the financeChart, but the xAxis cannot auto fill the blank space.
my codes as bellow:

    FinanceChart *c = new FinanceChart(width);
    c->setLegendStyle("normal", 9, Chart::Transparent, Chart::Transparent);
    c->setData(timeStamps, high, low, open, close, volData, 0);
    c->setBackground(chartBgColor);
    c->setBorder(Chart::Transparent);
    //c->setDateLabelSpacing(20);
    c->setDateLabelFormat("{value|yyyy}", "{value|yyyy-mm}", "{value|mm}", "{value|mm-dd}", "{value|mm-dd}", "{value|mm-dd hh:nn}", "{value|hh:nn:ss}");
    //c->setDateLabelFormat("", "", "", "", "", "", "");
    c->setDateLabelSpacing(10);
    XYChart *mainChart = c->addMainChart(getChartHeight());
    //mainChart->setPlotArea(5, 5, width - 5 -50, getChartHeight() - 50, -1, -1, Chart::Transparent, 0xcccccc);
    PlotArea *plotArea = mainChart->setPlotArea(leftBlank, topBlank, width - leftBlank - rightBlank,
                                                getChartHeight() - rightBlank, -1, -1,
                                                Chart::Transparent, Chart::Transparent);
    mainChart->setBackground(chartBgColor, Chart::Transparent);
    mainChart->setBorder(Chart::Transparent);
    mainChart->yAxis()->setTickDensity(40);
    mainChart->xAxis()->setTickDensity(80);
    mainChart->xAxis()->setTickLength(0);
    mainChart->xAxis()->setLabelStyle("arial.ttf", 9, 0xcccccc, 0);
    //mainChart->xAxis()->setLabelFormat("{value|hh:nn:ss}");
    mainChart->yAxis()->setLabelStyle("arial.ttf", 9, 0xcccccc, 0);
    mainChart->yAxis()->setTickLength(0);

    int areaColor = mainChart->linearGradientColor(0, plotArea->getTopY() + 20, 0, plotArea->getTopY() + plotArea->getHeight(), 0xa0ccffee, 0xff1c2329);
    AreaLayer *layer = mainChart->addAreaLayer(volData, areaColor);
    layer->setBorderColor(Chart::Transparent);
    LineLayer *lineLayer = mainChart->addLineLayer(volData, 0xccffdd);
    lineLayer->setLineWidth(2);

    int tlen = timeStamps.len;
    double maxValue[1], maxYValue[1], scatterDotValues[tlen];//, lineValues[2];
    maxValue[0] = timeStamps[tlen -1];
    maxYValue[0] = volData[volData.len - 1];
    for(int i = 0; i < tlen; i++)
    {
        scatterDotValues[i] = Chart::NoValue;
    }
    int deci = Common::Instance->getdecimal(Common::Instance->getCurrentMode(), currentCode);
    maxYValue[0] = Converter::Round(maxYValue[0], deci);
    scatterDotValues[tlen - 1] = maxYValue[0];


    int color = priceIsUp? 0xd73654 : 0x86bb37;
    ScatterLayer *layerDot = mainChart->addScatterLayer(DoubleArray(), DoubleArray(scatterDotValues, tlen), "", Chart::GlassSphere2Shape,11, color);
    //layerDot->setUseYAxis2();

    Mark *mark = mainChart->yAxis()->addMark(maxYValue[0], mainChart->dashLineColor(0xaaaaaa, Chart::DotLine),"");


    TextBox *textbox = layerDot->setDataLabelStyle("arialbd.ttf", 12, 0xffffff);

    textbox->setBackground(color, color, 1);

    textbox->setAlignment(Chart::Left);
    textbox->setPos(0, 0);


    /*
    CandleStickLayer *candle = c->addCandleStick(0x00ff00, 0xff0000);
    candle->setColors(0x00ff00, 0x00ff00, 0xff0000, 0xff0000);
    candle->setDataWidth(5);
    */
    delete viewer->getChart();
    viewer->setChart(c);

    CandleStickLayer *candle = c->addCandleStick(0x00ff00, 0xff0000);
    candle->setColors(0x00ff00, 0x00ff00, 0xff0000, 0xff0000);
    candle->setDataWidth(5);
chart2.png

  Re: how to fill the xAxis with time lables
Posted by Peter Kwan on Apr-07-2016 02:19
Hi hondodo,

The built-in labelling method of the FinanceChart object assumes the chart is at least for a few hours, and the closest label spacing is one label every hour.

For intraday charts, usually the timestamps will include the entire trading day (or at least a few hours), even though you may only have a few minutes of data. In this case, the x-axis of the chart will cover the entire trading day, and the chart will start from the left side. The hourly labels will look natural.

If you still want to create a financial chart with a short interval, you may add additional code for the x-axis labelling. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1459402202#N1459449695

Hope this can help.

Regards
Peter Kwan

  Re: how to fill the xAxis with time lables
Posted by hondodo on Apr-08-2016 14:51
I used the following code had slot my problem in my case, thank you ver much :
mainChart->xAxis()->setMultiFormat(Chart::StartOfMinuteFilter(10,0.5), "{value|h:nna}");