How to: Create Sparkline
The following example demonstrates how to create a sparkline in the Snap Report API.
- Call the IRichEditDocumentServer.LoadDocumentTemplate method to load the document template and open it for modification by calling the SubDocument.BeginUpdateCharacters method.
- Create a new SnapSparkline object by calling the ISnapFieldOwner.CreateSnSparkline method with the passed position to place the sparkline.
- Convert the created sparkline field to a Snap Field. To do that, use the ISnapFieldOwner.ParseField method. Note that without conversion, you will not be able to modify the sparkline.
- Start modifying the sparkline by calling the SnapEntity.BeginUpdate method.
- Specify the desired sparkline settings, such as view type (SnapSparkline.ViewType), color (SnapSparkline.Color), dimensions (SnapSparkline.Size), etc.
- Finalize the modification using the SnapEntity.EndUpdate method.
- Call the FieldCollection.Update method to update the document fields.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/snap-document-server-api-t429162
server.LoadDocumentTemplate("Template.snx")
server.Document.BeginUpdate()
Dim sparkline As SnapSparkline = server.Document.CreateSnSparkline(server.Document.Range.End, "UnitsInStock")
server.Document.ParseField(sparkline.Field)
sparkline.BeginUpdate()
sparkline.DataSourceName = "/Data Source 1.Products"
sparkline.ViewType = SparklineViewType.Line
sparkline.Color = System.Drawing.Color.Teal
sparkline.EndUpdate()
sparkline.Field.Update()
See Also