Category / Section
How can we convert the Excel chart to chart control?
1 min read
We do not have direct support for converting Excel chart to chart control. However we can do manually by using both XlsIO and Essential chart. You can enumerate the elements in of XlsIO chart and draw the chart with the equivalent chart using Essential chart. The below code illustrates the basic conversion of XLSIO Chart to Essential Chart:
C#
IChart chart = workbook.Charts.Add(); this.chartControl1.Text = chart.ChartTitle; for (int i =0; i < chart.Series.Count; i++) { ChartSeries ser = new ChartSeries(); int h = 0; int col=chart.Series[i].Values.Column; for (int j = chart.Series[i].Values.Row; j < chart.Series[i].Values.Count + chart.Series[i].Values.Row; j++) { h++; ser.Points.Add(h,chart.Series[i].Values[j, col].Number); } ser.Style.Interior = new ser.Name = ser.Text = chart.Series[i].Name; this.chartControl1.Series.Add(ser); }
VB
Dim chart As IChart = workbook.Charts.Add() Me.chartControl1.Text = chart.ChartTitle For i As Integer = 0 To chart.Series.Count - 1 Dim ser As ChartSeries = New ChartSeries() Dim h As Integer = 0 Dim col As Integer = chart.Series(i).Values.Column For j As Integer = chart.Series(i).Values.Row To chart.Series(i).Values.Count + chart.Series(i).Values.Row - 1 h += 1 ser.Points.Add(h,chart.Series(i).Values(j, col).Number) Next j ser.Text = chart.Series(i).Name Dim TempName As ser.Name = New ser.Name = ser.Text ser.Style.Interior = New ser.Name Me.chartControl1.Series.Add(ser) Next i
Here is the sample for your reference:
http://www.syncfusion.com/downloads/support/directtrac/87766/XlsIO_ChartControl652608821.zip