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

Message ListMessage List     Post MessagePost Message

  Bar chart 1-10 scale ‘starting appearance’ at 5 possible?
Posted by Franky on May-15-2024 16:52
Attachments:
Hello Peter,

We still use the asp/com-variant of your great product and are wondering if such a bar chart as the picture attached is possible to make. And use different colors per groups of three bars in one chart. Can you give us hints to create such a bar graph?

Kind regards,

Franky
09B67B0C-F1EC-4A89-AA83-02153321234E.jpeg

  Re: Bar chart 1-10 scale ‘starting appearance’ at 5 possible?
Posted by Peter Kwan on May-16-2024 16:31
Attachments:
Hi Franky,

I tried to start from a horizontal box chart, and I get the attached chart. It should be similar to your requirement.


Set cd = CreateObject("ChartDirector.API")

data = Array(5, 4, 6)

Set c = cd.XYChart(350, 150)
Call c.setPlotArea(25, 25, 300, 100, &H99CCFF, -1, cd.Transparent, cd.Transparent, cd.Transparent)
Call c.swapXY()

'Axis scale
Call c.yAxis().setLinearScale(0, 10)
Call c.yAxis().setColors(cd.Transparent, cd.Transparent)
Call c.xAxis().setLinearScale(0, UBound(data))
Call c.xAxis().setColors(cd.Transparent, cd.Transparent)
Call c.xAxis().setMargin(5, 5)

'The bar labels
Set labelLayer = c.addScatterLayer(Nothing, cd.ArrayMath(data).subtract(data).add(5).result(), "", cd.SquareSymbol, 0)
Call labelLayer.addExtraField(data)
Call labelLayer.setDataLabelFormat("{field0}")
Call labelLayer.setDataLabelStyle("Arial Bold", 10).setAlignment(cd.Center)

'The bars
For i = 0 To Ubound(data)
if data(i) = 5 Then
    Set layer = c.addBoxLayer(Array(4.5), Array(5.5))
ElseIf data(i) < 5 Then
Set layer = c.addBoxLayer(Array(data(i) - 0.5), Array(5.5))
ElseIf data(i) > 5 Then
Set layer = c.addBoxLayer(Array(data(i) + 0.5), Array(4.5))
End If

Call layer.setXData(Array(i))
If data(i) <> 5 Then Call layer.setRoundedCorners(9999, 0)
Next

' Output the chart as usual
Response.ContentType = "image/png"
Response.BinaryWrite c.makeChart2(cd.PNG)
Response.End
test.png

  Re: Bar chart 1-10 scale ‘starting appearance’ at 5 possible?
Posted by Franky on May-17-2024 17:10
Hello Peter,

This is great, thank you so much for helping us making this work splendidly!

Kind regards,

Franky