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

Message ListMessage List     Post MessagePost Message

  Zooming Bar Charts
Posted by Krishnan on Apr-14-2008 17:04
Attachments:
Hi -

First let me explain what I am looking for.

I have around 200 items and their sales for a given month. Let us have the item names like a,b,c etc.

I want to incorporate the bar charts for showing the items sales data.
Since 200 is a large no, it is not possible/readable to show all of them at once.

So I decided to use the zoom/scrolling feature (zoomscrolldemo2.aspx of the demo).

The first time I want to show all the 200 items in the graph. Then zoom & scroll.

The first time it comes alright. The item names in the xaxis is displayed correctly (a,b,c..)

But when i zoom in the item names becomes something like this (0,b,c,d,e,5,g,h,i,j,10...)

Why is that happening? I want the item names to be like a,b,c,d even if i zoom in/out.

I am attaching a screen shot of the same. Also including the code for quick reference.

Please help me out.

Best Regards,
-Krish
Scroll.JPG
ZoomProblem.aspx
ZoomProblem.aspx

21.31 Kb

  Re: Zooming Bar Charts
Posted by Peter Kwan on Apr-15-2008 01:14
Hi Krishnan,

The issue is because in your case, the x-axis is a "label based axis" and not really a linear x-axis. So the setLinearScale code may not work for the x-axis. There are several methods to solve the problem. For following is one approach.

'remove the setLinearScale line for the x-axis, replace with the following code
'c.xAxis().setLinearScale(xScaleMin, xScaleMax)

'round the x-coordinates to integers as the x-axis is label based, and not really numeric
Dim xIndexStart As Integer = Math.Round(xScaleMin)
Dim xIndexEnd As Integer = Math.Round(xScaleMax)

'get the labels for the above integer range
Dim visibleXLabels(xIndexEnd - xIndexStart) As String
Array.Copy(labels, xIndexStart, visibleXLabels, 0, xIndexEnd - xIndexStart + 1)

'use the labels as the axis scale
c.xAxis().setLinearScale2(xIndexStart, xIndexEnd, visibleXLabels)

Hope this can hlep.

Regards
Peter Kwan

  Re: Zooming Bar Charts
Posted by Krishnan on Apr-15-2008 10:40
Hi Peter -

Thank you very much. That indeed did the trick.

Regards,
-Krish

  Re: Zooming Bar Charts
Posted by Krishnan on Apr-15-2008 11:35
Attachments:
Hi Peter -

I have one more problem in the same zoom features. In addition to the bar chart I have also added a line layer (Pareto). Initially the linelayer is within the plot area.

But when I zoom the line layer goes beyond the plot area on both sides.

Please find attached the screen shot and also the code for the drawChart.

Your help is highly appreciated.

Best Regards,
-Krish
Zoom.JPG
DrawChart.txt
Private Sub drawChart(viewer As WebChartViewer)

        Dim data() As Double = {219, 156, 141, 116, 74, 53, 36, 24, 24, 18, 12, 9, 219, 156, 141, 116, 74, 53, 36, 24, 24, 18, 12, 9, 219, 156, 141, 116, 74, 53, 36, 24, 24, 18, 12, 9, 219, 156, 141, 116, 74, 53, 36, 24, 24, 18, 12, 9, 219, 156, 141, 116, 74, 53, 36, 24, 24, 18, 12, 9, 219, 156, 141, 116, 74, 53, 36, 24, 24, 18, 12, 9}
        Dim data2() As Double = {24.83, 42.48, 58.47, 71.61, 79.99, 85.99, 90.07, 95.54, 92.82, 97.58, 98.98, 100.0, 24.83, 42.48, 58.47, 71.61, 79.99, 85.99, 90.07, 95.54, 92.82, 97.58, 98.98, 100.0, 24.83, 42.48, 58.47, 71.61, 79.99, 85.99, 90.07, 95.54, 92.82, 97.58, 98.98, 100.0, 24.83, 42.48, 58.47, 71.61, 79.99, 85.99, 90.07, 95.54, 92.82, 97.58, 98.98, 100.0, 24.83, 42.48, 58.47, 71.61, 79.99, 85.99, 90.07, 95.54, 92.82, 97.58, 98.98, 100.0, 24.83, 42.48, 58.47, 71.61, 79.99, 85.99, 90.07, 95.54, 92.82, 97.58, 98.98, 100.0}

        ' The labels for the chart
        Dim labels() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1", "i1", "j1", "k1", "l1", "a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2", "i2", "j2", "k2", "l2", "a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3", "i3", "j3", "k3", "l3", "a4", "b4", "c4", "d4", "e4", "f4", "g4", "h4", "i4", "j4", "k4", "l4", "a5", "b5", "c5", "d5", "e5", "f5", "g5", "h5", "i5", "j5", "k5", "l5"}


        ' Create a XYChart object of size 400 x 225 pixels. Use golden background color,
        ' with a 2 pixel 3D border.
        Dim c As XYChart = New XYChart(600, 425, Chart.goldColor(), -1, 2)

        ' Add a title box using Arial Bold/11 pt font. Set the background color to
        ' metallic blue (9999FF). Use a 1 pixel 3D border.
        c.addTitle("Hardware Defects", "Arial Bold", 11).setBackground( _
            Chart.metalColor(&H9999FF), -1, 1)

        ' Set the plotarea at (50, 40) and of 300 x 150 pixels in size, with a silver
        ' background color.
        c.setPlotArea(50, 40, 500, 350, Chart.silverColor())

        ' Add a line layer for the pareto line
        Dim lineLayer As LineLayer = c.addLineLayer()
        
        
        ' Add the pareto line using the scaled data. Use deep blue (0x80) as the line
        ' color, with light blue (0x9999ff) diamond symbols
        lineLayer.addDataSet(data2, &H80 _
            ).setDataSymbol(Chart.DiamondSymbol, 9, &H9999FF)

        '' Set the line width to 2 pixel
        lineLayer.setLineWidth(2)
        lineLayer.setUseYAxis2(True)

        '' Tool tip for the line layer
        lineLayer.setHTMLImageMap("", "", "title='Top {={x}+1} items: {value|2}%'")


        Dim barLayer As BarLayer = c.addBarLayer(data, c.xZoneColor(4.5, &H80FF3333, &H0))

        ' Set soft lighting for the bars with light direction from the right
        barLayer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Right))
        
        ' Tool tip for the bar layer
        barLayer.setHTMLImageMap("", "", "title='{xLabel}: {value} pieces'")

        ' Set the labels on the x axis.
        c.xAxis().setLabels(labels)
        
        'c.xAxis.addZone(-1, 4, Chart.silverColor)
        'c.xAxis.addZone(4, 4, &H0)
        'c.yAxis2.addZone(80, 80, &H0)
        
                 
        'this is for adding color to the entire zone
        'c.xAxis.addZone(0, 4, Chart.silverColor)
        'c.xAxis.addZone(3.9, 12, &H0)
        'c.yAxis2.addZone(80, 80, &H0)
        'c.yAxis2.addZone(81, 120, &H0)

        ' Set the label format of the y-axis label to include a percentage sign
        c.yAxis().setLabelFormat("{value}")

        ' Add a title to the secondary y-axis
        c.yAxis2().setTitle("Frequency")

        ' Set the secondary y-axis label foramt to show no decimal point
        c.yAxis2().setLabelFormat("{value|%}")

    If viewer.GetCustomAttr("minY") = "" Then
        ' The axis scale has not yet been set up. This means this is the first time the chart is
        ' drawn and it is drawn with no zooming. We can use auto-scaling to determine the
        ' axis-scales, then remember them for future use.

        ' explicitly auto-scale axes so we can get the axis scales
            c.layout()
            ' save the axis scales for future use
            viewer.SetCustomAttr("minX", c.xAxis().getMinValue())
            viewer.SetCustomAttr("maxX", c.xAxis().getMaxValue())
            viewer.SetCustomAttr("minY", c.yAxis().getMinValue())
            viewer.SetCustomAttr("maxY", c.yAxis().getMaxValue())
    Else
        ' Retrieve the original full axes scale
            Dim minX As Double = CDbl(viewer.GetCustomAttr("minX"))
            Dim maxX As Double = CDbl(viewer.GetCustomAttr("maxX"))
            Dim minY As Double = CDbl(viewer.GetCustomAttr("minY"))
            Dim maxY As Double = CDbl(viewer.GetCustomAttr("maxY"))

        ' Compute the zoomed-in axis scales by multiplying the full axes scale with the view port
        ' ratio
            Dim xScaleMin As Double = minX + (maxX - minX) * viewer.ViewPortLeft
            Dim xScaleMax As Double = minX + (maxX - minX) * (viewer.ViewPortLeft + _
               viewer.ViewPortWidth)
            Dim yScaleMax As Double = maxY - (maxY - minY) * viewer.ViewPortTop
            Dim yScaleMin As Double = maxY - (maxY - minY) * (viewer.ViewPortTop + _
            viewer.ViewPortHeight)

            ' Set the axis scales
            'c.xAxis().setLinearScale(xScaleMin, xScaleMax)
            Dim xIndexStart As Integer = Math.Round(xScaleMin)
            Dim xIndexEnd As Integer = Math.Round(xScaleMax)

            Dim yIndexStart As Integer = Math.Round(yScaleMin)
            Dim yIndexEnd As Integer = Math.Round(yScaleMax)

            
            Dim visibleXLabels(xIndexEnd - xIndexStart) As String
            Array.Copy(labels, xIndexStart, visibleXLabels, 0, xIndexEnd - xIndexStart + 1)

            c.xAxis().setLinearScale2(xIndexStart, xIndexEnd, visibleXLabels)

            'c.yAxis().setLinearScale(yScaleMin, yScaleMax)
            'c.yAxis2().setLinearScale(yIndexStart, yIndexEnd)
            

        ' By default, ChartDirector will round the axis scale to the tick position. For zooming, we
        ' want to use the exact computed axis scale and so we disable rounding.
            c.xAxis().setRounding(False, False)
            c.yAxis().setRounding(False, False)
    End If

        
    ' Create the image
    ' Output the chart
    viewer.Image = c.makeWebImage(Chart.PNG)

    ' Include tool tip for the chart
    viewer.ImageMap = c.getHTMLImageMap("", "", _
        "title='[{dataSetName}] Alpha = {x|G}, Beta = {value|G}'")

End Sub

  Re: Zooming Bar Charts
Posted by Peter Kwan on Apr-15-2008 16:42
Hi Krishnan,

In the original "Zooming and Scrolling Demonstration (2)" sample code there should be the following line, which clips the chart to the plot area:

' Enable clipping mode to clip the part of the data that is outside the plot area.
c.setClipping()

Adding the above line should solve the problem.

Hope this can help.

Best Regards,
Peter Kwan

  Re: Zooming Bar Charts
Posted by Krishnan on Apr-16-2008 10:39
Hi Peter -

Thanks. That did the trick.

Best Regards,
-Krish

  Re: Zooming Bar Charts
Posted by Krishnan on Apr-16-2008 16:45
Attachments:
Hi Peter -

I am stuck up with one more problem.

I am trying to incorporate dynamic data with zoom options.

Initially I have only 12 items.

the graph is coming up well and also the zoom features are working fine.



On Page post back I am adding more data (72 items).

Then the graph is coming up with only 12 items and not 72.

Kindly help me figure this out.

Attaching the code for your reference.

Best Regards,
-krish
zoomscrolldemo2.aspx
zoomscrolldemo2.aspx

25.05 Kb

  Re: Zooming Bar Charts
Posted by Peter Kwan on Apr-16-2008 19:35
Hi Krishnan,

In your current code, when the chart is first drawn, the code saves the x and y axis ranges and use it as the total ranges of the axes. Subsequently, when you zoom into the chart, the code can retreive the total axis ranges and use them to compute the visible axis ranges.

In your case, if the x-axis range changes, you may also update the saved ranges to reflect the modified axis range. For example:

        If IsPostBack Then
            suppliercodes = biglabels1
            suppliernames = biglabels2
            ytmspend = bigdata1
            CumulativeOverallspend = bigdata2
            viewer.SetCustomAttr("minX", 0)
            viewer.SetCustomAttr("maxX", UBound(suppliercodes))
        Else
            suppliercodes = smalllabels1
            suppliernames = smalllabels2
            ytmspend = smalldata1
            CumulativeOverallspend = smalldata2
        End If

Hope this can help.

Regards
Peter Kwan