Skip to main content Skip to footer

HowTo: Custom Sparkline in Spread for WinForms

Spread for Winforms provides a feature of creating sparklines wherein we can create a small graph in a cell that uses data from a range of cells. The data for the sparkline is limited to one column or row of values within the same SpreadSheet. We can set the SparklineType to column, line, or winloss etc. Here in this blog we will explain an approach to create custom winloss SparklineType from an external datasource wherein the data is fetched from some other sheet of FpSpread.

STEP 1 - Create Custom Class Inherited from ExcelSparkLine

First of all we need to create a CustomExcelSparkline class inheriting from ExcelSparkline class which takes SheetView as datasource as given below:-

class CustomExcelSparkline : ExcelSparkline  
    CellRangeSegmentData innerData;  
    public CustomExcelSparkline(int row, int column, SheetView source)  
        : base(row, column, string.Empty)  
        innerData = new CellRangeSegmentData(source, 0, 0, source.RowCount, source.ColumnCount, null);  
    public override object GetSparkLineData()  
        return innerData;  

STEP 2 - Use Custom class to Create winloss SparklineType

Now we will use this CustomExcelSparkline to create winloss SparklineType which takes data from some other sheet of Spread on which it is drawn:-

private void Form1_Load(object sender, EventArgs e)  
    List<Double> dlist = new List<double>();  

    SheetView sv = new SheetView();  
    sv.Visible = false;  
    sv.SheetName = Guid.NewGuid().ToString();  
    sv.DataSource = dlist;  
    fpSpread1.Sheets[0].RowCount = 10;  
    fpSpread1.Sheets[0].ColumnCount = 10;  
    for (int r = 0; r < fpSpread1.Sheets[0].RowCount; r++)  
        FarPoint.Win.Spread.SparklineType type = SparklineType.Column;  
        if (r % 3 == 1)  
            type = SparklineType.Line;  
        else if (r % 3 == 2)  
            type = SparklineType.Winloss;  
        FarPoint.Win.Spread.ExcelSparklineGroup esg = new FarPoint.Win.Spread.ExcelSparklineGroup(new FarPoint.Win.Spread.ExcelSparklineSetting(), type);  
        for (int c = 0; c < fpSpread1.Sheets[0].ColumnCount; c++)  
            CustomExcelSparkline es = new CustomExcelSparkline(r, c, sv);  

winloss SpreadSparkline winloss SpreadSparkline Download sample for detailed implementation : DownloadSample_CS DownloadSample_VB


comments powered by Disqus