Small Basic – Chart Extension

So far it just has a pie and doughnut variant. The C# extension source code is also available for download if you want to see how it is done or even modify to create your own.

Sample Code

GraphicsWindow.Width = 800

GraphicsWindow.Height = 400

GraphicsWindow.Title = "Click a segment"

data = ""

For i = 1 To 12

data["My Test Data "+i] = Math.GetRandomNumber(10)

EndFor

GraphicsWindow.BackgroundColor = "Black"

GraphicsWindow.FontName = "Segoe UI"

GraphicsWindow.FontBold = "False"

GraphicsWindow.PenColor = "White"

chart1 = LDChart.AddChart(400,400)

LDChart.Properties(chart1,"doughnut",1)

LDChart.Legend(chart1,1,"legend_percent","false")

LDChart.ColourMap(chart1,0,0.3,0.6,"hue",0,1,"LightBlue")

LDChart.SetData(chart1,data)

GraphicsWindow.BackgroundColor = LDColours.WhiteSmoke

GraphicsWindow.FontName = "Segoe UI"

GraphicsWindow.FontBold = "False"

GraphicsWindow.PenColor = "Red"

chart2 = LDChart.AddChart(400,400)

Shapes.Move(chart2,400,0)

LDChart.Properties(chart2,"pie",1.1)

LDChart.Legend(chart2,1.5,"percent","false")

LDChart.ColourMap(chart2,0,0,0.6,"lightness",0.8,0.2,"")

LDChart.SetData(chart2,data)

LDChart.ValueClicked = OnValueClicked

Sub OnValueClicked

LDChart.Highlight(LDChart.LastChart,LDChart.LastLabel,0.1)

EndSub

LDShapes.SetShapeEvent(chart1)

LDShapes.SetShapeEvent(chart2)

LDShapes.ShapeEvent = OnShapeEvent

Sub OnShapeEvent

If (LDShapes.LastEventType = "MouseLeave") Then

LDChart.Update(LDShapes.LastEventShape)

EndIf

EndSub

Here is a screen shot of the sample that comes with the extension download (other-samples/LDChart,sb).

The LDChart object includes lots of customisation and colour control (using HSL colour tables) and an event to detect a segment clicked as well as highlighting segments like the 10.1% segment on the right hand chart.

Here is the API

AddChart(width,height)Create a chart control.The current GraphicsWindow.BackgroundColor will be used for the background.The current GraphicsWindow.PenColor and Font properties will be used for the label text.For Example:GraphicsWindow.FontName = "Segoe UI"GraphicsWindow.FontBold = "False"width The width of the chart.height The height of the chart.returns The chart shape name.