This question is locked. New answers and comments are not allowed.
I have a chart that is bound to a datasource. When data is updated in the table, the chart is not refreshed or updated. I have tried:
.update()
.updategraphics()
.refresh()
And also:
.datasource= mybindingsource
.databind()
The latter causes a large red X to be displayed instead of a chart.
Any help?
.update()
.updategraphics()
.refresh()
And also:
.datasource= mybindingsource
.databind()
The latter causes a large red X to be displayed instead of a chart.
Any help?
4 Answers, 1 is accepted
0
Hello Michelle,
Just calling the DataBind() method should suffice. Here is the code I used to test the chart:
The designer only contains a chart and a button.
If you have a more complicated scenario in which calling the DataBind does not work, please, open a support ticket and attach a sample project. Note, that attachments in the forum threads are not allowed.
Sincerely yours,
Evtim
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Just calling the DataBind() method should suffice. Here is the code I used to test the chart:
public partial class Form1 : Form |
{ |
private DataTable table; |
public Form1() |
{ |
InitializeComponent(); |
table = InitTable(); |
this.radChart1.DataSource = table; |
this.radChart1.DataBind(); |
} |
private static DataTable InitTable() |
{ |
DataTable table = new DataTable(); |
Random r = new Random(table.GetHashCode()); |
table.Columns.Add("First", typeof(int)); |
table.Columns.Add("Second", typeof(int)); |
for (int i = 0; i < 10; i++) |
{ |
DataRow row = table.NewRow(); |
row["First"] = r.Next(10, 100); |
row["Second"] = r.Next(110, 200); |
table.Rows.Add(row); |
} |
return table; |
} |
private void button1_Click(object sender, EventArgs e) |
{ |
int value = (int)this.table.Rows[0][0]; |
value += 100; |
this.table.Rows[0][0] = value; |
this.radChart1.DataBind(); |
} |
} |
The designer only contains a chart and a button.
If you have a more complicated scenario in which calling the DataBind does not work, please, open a support ticket and attach a sample project. Note, that attachments in the forum threads are not allowed.
Sincerely yours,
Evtim
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Michelle
Top achievements
Rank 1
answered on 01 Jun 2009, 03:44 PM
Thank you for your response. My situation was more complicated. Unfortunately, my period of support has ended which is why I have posted this on the community forums instead of opening a support ticket. Fortunately, I have resolved the issue myself :)
For a little more background information, I will explain a bit more of what was happening and share the workaround/solution I have identified.
Background Information: I have a form with a Chart (RadChart1) bound to a table (ChartDimensions). I also have a listbox (LstShape) on the side of the form. The table ChartDimensions includes the X and Y locations required to draw a Line Chart to give the desired shape. Upon selection of an item from the LstShape, ChartDimensions has a query applied to return only the X and Y coordinates relative to the requested shape. The initial shape would load in the chart fine, but subsequent selections made no update to the chart. Initially, I applied only the methods I posted earlier, but could not identify why I was getting the giant red X in place of my chart. I thought it was possible that the RadChart1 was having difficulty finding cohesiveness in the data, thus giving me the X.
Resolution: I thought maybe I would try to clear the chart entirely before using the .databind() method. To my surprise, this worked! However, the results displayed left much to be desired. The chart remained a line chart, but it now had 3 series of data (the initial one had only one series). I thought then that maybe the idea would be to NOT clear the chart, but rather remove the series and then repopulate with a new series. This rendered the proper data points, but for whatever reason, this made the chart default type a Bar Chart. It also displayed the series labels again, which I did not want displayed. I handled this with 2 lines of code following the rebinding of the datasource.
Below is the code as I have in my LstShape_SelectedIndexChanged event:
I hope this can be of some assistance. If there is an easier workaround than the one I have provided, please let me know!
For a little more background information, I will explain a bit more of what was happening and share the workaround/solution I have identified.
Background Information: I have a form with a Chart (RadChart1) bound to a table (ChartDimensions). I also have a listbox (LstShape) on the side of the form. The table ChartDimensions includes the X and Y locations required to draw a Line Chart to give the desired shape. Upon selection of an item from the LstShape, ChartDimensions has a query applied to return only the X and Y coordinates relative to the requested shape. The initial shape would load in the chart fine, but subsequent selections made no update to the chart. Initially, I applied only the methods I posted earlier, but could not identify why I was getting the giant red X in place of my chart. I thought it was possible that the RadChart1 was having difficulty finding cohesiveness in the data, thus giving me the X.
Resolution: I thought maybe I would try to clear the chart entirely before using the .databind() method. To my surprise, this worked! However, the results displayed left much to be desired. The chart remained a line chart, but it now had 3 series of data (the initial one had only one series). I thought then that maybe the idea would be to NOT clear the chart, but rather remove the series and then repopulate with a new series. This rendered the proper data points, but for whatever reason, this made the chart default type a Bar Chart. It also displayed the series labels again, which I did not want displayed. I handled this with 2 lines of code following the rebinding of the datasource.
Below is the code as I have in my LstShape_SelectedIndexChanged event:
'create new series for the chart |
Dim series As New Telerik.Charting.ChartSeries |
Try |
'remove all existing chart series |
RadChart1.Series.Clear() |
'map series values |
series.DataXColumn = Me.AISCDataSet.ChartDimensions.Columns(1).ColumnName |
series.DataYColumn = Me.AISCDataSet.ChartDimensions.Columns(2).ColumnName |
'add new series to chart |
RadChart1.Series.Add(series) |
'rebind data |
RadChart1.DataBind() |
'reset chart type to LINE and remove series labels |
RadChart1.DefaultType = Telerik.Charting.ChartSeriesType.Line |
RadChart1.Series(0).Appearance.LabelAppearance.Visible = False |
Catch ex As Exception |
MsgBox(ex.Message) |
End Try |
I hope this can be of some assistance. If there is an easier workaround than the one I have provided, please let me know!
0
Accepted
Hi Michelle,
I am glad you have found a solution to the problem. I would just suggest, instead of changing the RadChart.DefaultType, to just set the series.Type to Bar and hide the labels before data bind:
Best,
Evtim
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I am glad you have found a solution to the problem. I would just suggest, instead of changing the RadChart.DefaultType, to just set the series.Type to Bar and hide the labels before data bind:
Dim series As New Telerik.Charting.ChartSeries |
Try |
'remove all existing chart series |
RadChart1.Series.Clear() |
'map series values |
series.DataXColumn = Me.AISCDataSet.ChartDimensions.Columns(1).ColumnName |
series.DataYColumn = Me.AISCDataSet.ChartDimensions.Columns(2).ColumnName |
'set series type |
series.Type = ChartSeriesType.Line |
'hide labels |
series.Appearance.LabelAppearance.Visible = False |
'add new series to chart |
RadChart1.Series.Add(series) |
'rebind data |
RadChart1.DataBind() |
Catch ex As Exception |
MsgBox(ex.Message) |
End Try |
Best,
Evtim
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Michelle
Top achievements
Rank 1
answered on 02 Jun 2009, 01:30 PM
Thanks!