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

Message ListMessage List     Post MessagePost Message

  How to arrange x-axis labels for not to overlap
Posted by Dilip Agarwal on Aug-13-2013 18:59
Attachments:
Hi Peter, could you please tell me how can I arrange labels on x-axis so that they will not overlap each other. Also When I zoom the graph then found that some numerical digits shows on x-axis while I have set only strings on the x-axis. could you please tell me why these numeric digits shows.

I have attach images MultiColBar.jpeg for original chart, multicolbarinZoom1.jpeg is after first zoom for showing that string labels are set on the x-axis, MultiColBarInZoom2.jpeg is after second zoom for showing that numeric digits are shows on more zoom.

Some code snippet is as below


Set c = cd.XYChart(960, 370, &Hffffc0, &H000000)
    Call c.setPlotArea(30, 30, 900, 280).setBackground(&Hffffff)
     Call c.setClipping()
    Call c.addTitle(graphTitle, "arialbd.ttf", 8).setBackground(&Hffff40, 0)
    Call c.yAxis().setLabelFormat("{value}")
    Call c.xAxis().setLabels(timeArray)
    Call c.xAxis().setLabelFormat("{value}")
    Call c.xAxis().setLabelStyle("arial.ttf", 8, cd.TextColor, 90)

    Set layer = c.addBarLayer2(cd.Side, 4)
    Dim i

    legendStrForCustomAttr = ""
    for i=0 to UBound(legendArray)
        if legendsState(i) = "T" then
            Call layer.addDataSet(baseDataArray(i), baseColorArray(i), legendArray(i))
        end if
    next
    for i=0 to UBound(legendArray)
        if i <> UBound(legendArray) then
            legendStrForCustomAttr =legendStrForCustomAttr& legendArray(i) &"::"&baseColorArrHTML(i)&"::"&legendsState(i)&",,"
        else
            legendStrForCustomAttr = legendStrForCustomAttr&legendArray(i) &"::"&baseColorArrHTML(i)&"::"&legendsState(i)
        end if

    next

    Call viewer.setCustomAttr("legendStr",legendStrForCustomAttr)
    Call c.xAxis().setTickDensity(10)
    Call viewer.syncLinearAxisWithViewPort("x", c.xAxis())
    Call viewer.syncLinearAxisWithViewPort("y", c.yAxis())
    chartQuery = c.makeSession(Session, viewer.Id)
    viewer.ImageUrl = "getchart.asp?" & chartQuery

MultiColBar.JPG
multicolbarinZoom1.JPG
MultiColBarInZoom2.JPG

  Re: How to arrange x-axis labels for not to overlap
Posted by Dilip Agarwal on Aug-13-2013 19:53
Hi Peter, I fix the issue of overlaping with c.xAxis().setLabelStep. But still I don't know why numeric digits appear on the x-axis when zoom the graph.

  Re: How to arrange x-axis labels for not to overlap
Posted by Peter Kwan on Aug-14-2013 00:41
Hi Dilip,

The issue is because of using syncLinearAxisWithViewPort for the x-axis. As the x-axis is
not a linear axis in your case, the syncLinearAxisWithViewPort should not be used. See:

http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_support&thread=1373960759#N1374010998

The code in the above thread is in C++. For your case in VBScript, it is probably like:

'Replace the setLabels(timeArray) and syncLinearAxisWithViewPort("x", c.xAxis()) with the
followings:

Call viewer.setFullRange("x", 0, UBound(timeArray))

startLabelIndex = viewer.getValueAtViewPort("x", viewer.ViewPortLeft);
endLabelIndex = viewer.getValueAtViewPort("x", viewer.getViewPortLeft +
viewer.getViewPortWidth)
Call c.xAxis().setLinearScale(startLabelIndex, endLabelIndex, cd.NoValue)

' Add the labels with the range
For i = Int(startLabelIndex + 0.9999) to endLabelIndex
    Call c.xAxis().addLabel(i, timeArray(i))
Next

(*** Note: If you need to use setLabelStep, instead of using setLabelStep, you may
consider to add a Step clause in the For loop above.)

Hope this can help.

Regards
Peter Kwan

  Re: How to arrange x-axis labels for not to overlap
Posted by Dilip Agarwal on Aug-14-2013 17:30
Thanks Peter, could you please elaborate more how to add step clause in the for loop as if I need to show 20 labels from thousands of labels at a time on the axis

  Re: How to arrange x-axis labels for not to overlap
Posted by Peter Kwan on Aug-15-2013 02:35
Hi Dilip,

If you want to show at most 20 labels, the step must be:

Dim myStep As Integer = (Int(endLabelIndex) - Int(startLabelIndex + 0.9999)) \\  20 + 1

You may just apply the stepping in the For loop:

For i = Int(startLabelIndex + 0.9999) to endLabelIndex Step myStep
.....

Hope this can help.

Regards
Peter Kwan