How to use charts in Resolver One
We can easily use charts in Resolver One by combining an external charting library and image worksheets. Here's an example, using the Open Source library ZedGraph.
To get this running yourself, download the dll-only distribution of ZedGraph. Put the ZedGraph.dll into a directory that is on your PATH.
In the Resolver One code paste:
import clr
clr.AddReference("ZedGraph")
from System import Math
from System.Drawing import Bitmap, Graphics, RectangleF
from ZedGraph import GraphPane, PointPairList, SymbolType
chart = GraphPane(RectangleF(0, 0, 640, 480), "Graph Title", "X Title", "Y Title" )
pointPairList = PointPairList()
for x in range(50):
y = Math.Sin(x / 10.0)
pointPairList .Add( x, y )
chart.AddCurve("Sine Wave", pointPairList , Color.Blue, SymbolType.Diamond)
g = Graphics.FromImage(Bitmap(1, 1))
chart.AxisChange(g)
image = chart.GetImage()
workbook.AddImageWorksheet("CHART", image)
Straight away, you should see a new worksheet labelled CHART (RESULT) which holds the chart.
Here's a step-by-step explanation of how that code works:
- Load the ZedGraph assembly.
import clr
clr.AddReference("ZedGraph")
- Create a chart.
chart = GraphPane(RectangleF(0, 0, 640, 480), "Graph Title", "X Title", "Y Title")
- Fill it with some data.
pointPairList = PointPairList()
for x in range(50):
y = Math.Sin(x / 10.0)
pointPairList .Add( x, y )
or if you want to use data from the grid:
pointPairList = PointPairList()
sheet1 = workbook["Sheet1"]
for col in sheet1.Cols:
pointPairList.Add(col[1], col[2])
- Use the library's capability of retrieving an image.
image = chart.GetImage()
- Create an image worksheet.
workbook.AddImageWorksheet("CHART", image)
Chart Director
ChartDirector is a commercial charting component; here, by way of comparison with ZedGraph, is how you might use it in your Resolver One workbook:
import clr
clr.AddReference("netchartdir")
from ChartDirector import PieChart
from System.Collections import ArrayList
chart = PieChart(300, 300)
chart.setPieSize(150, 140, 100)
data = ArrayList()
labels = ArrayList()
sheet1 = workbook["Sheet1"]
for row in sheet1.Rows:
labels.Add(str(row[1]))
data.Add(row[2])
chart.setData(data.ToArray(type(2.0)), labels.ToArray(str))
image = chart.makeImage()
workbook.AddImageWorksheet("CHART", image)
Comments
If you have comments, questions or suggestions about any of the Resolver One documentation, please post them to the Documentation Suggestions Forum.

