We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Using Charts

i tried to use the chart object acording to the example of https://help.syncfusion.com/windowsforms/chart/getting-started?cs-save-lang=1&cs-lang=vb

But it dos not work. here is my code.
i have a datatable with data, 2 columns "Mes" and "Total"

With Graf_3
            Dim dataSeriesModel As CategoryAxisDataBindModel = New CategoryAxisDataBindModel(oPane.Vendas_Ano(2015, 0))
            dataSeriesModel.CategoryName = "Mes"
            dataSeriesModel.YNames = New String() {"Total"}
            Dim chartSeries As ChartSeries = New ChartSeries("Total")
            chartSeries.CategoryModel = dataSeriesModel
            .PrimaryXAxis.ValueType = ChartValueType.Category
            .Refresh()
        End With

can some one give an example in vb.net that uses a 2 column datatable to draw a chart ?

thanks
Ricardo

5 Replies

BP Baby Palanidurai Syncfusion Team April 30, 2019 12:06 PM UTC

Hi Ricardo, 

Greetings from Syncfusion. 

We have analyzed your query. Based on your requirement, we have prepared a sample in VB.NET. Please find the below code snippet to achieve this requirement, 

Dim dataSource As New BindingList(Of SalesData)() 
dataSource.Add(New SalesData("2000", 3)) 

Dim dataSeriesModel As New CategoryAxisDataBindModel(dataSource) 
dataSeriesModel.CategoryName = "Mes" 
dataSeriesModel.YNames = New String() { "Total" } 
Dim chartSeries As New ChartSeries("Total") 
chartSeries.CategoryModel = dataSeriesModel 
Me.chart1.PrimaryXAxis.ValueType = ChartValueType.Category 
Me.chart1.Series.Add(chartSeries) 
Me.Controls.Add(chart1) 

Screenshot: 
 


If the above sample doesn’t meet your requirement, kindly revert us with clear details about requirement. Thus will be helpful in furthermore analysis and provide you the solution sooner. 

Regards, 
Baby. 



RA Ricardo Abranches May 5, 2019 11:28 AM UTC

Hello Baby
It did not solve my problem, but gave me the clues to solve it.
However, it raised a new problem. When using ".Series.Add (chartSeries)" each time the chart is updated, a series is created. How can I do to update the values of the created series?


BP Baby Palanidurai Syncfusion Team May 6, 2019 08:42 AM UTC

Hi Ricardo, 
  
We have analyzed your query. Based on your requirement, we have prepared a sample with button click. In that sample, initially loaded a chart with single point. Then button click we have changed the chart series points values and assigned to the already created series instead of creating again. And then redraw the charts. 
 
Please find the below code snippet to achieve this requirement, 
 
Private buttonOk As New Button() 
Private chart1 As ChartControl = New Syncfusion.Windows.Forms.Chart.ChartControl() 
Public Sub New() 
              Me.buttonOk.Text = "Click to Change data" 
              AddHandler Me.buttonOk.Click, AddressOf ButtonOk_Click 
              Me.buttonOk.Width = 200 
              Me.Size = New Size(1200, 500) 
              Me.chart1.Location = New Point(10, 40) 
              Me.chart1.Size = New Size(1100, 400) 
              Dim dataSource As New BindingList(Of SalesData)() 
              dataSource.Add(New SalesData("2000", 3)) 
              Dim dataSeriesModel As New CategoryAxisDataBindModel(dataSource) 
              dataSeriesModel.CategoryName = "Mes" 
              dataSeriesModel.YNames = New String() { "Total" } 
              Dim chartSeries As New ChartSeries("Total") 
              chartSeries.CategoryModel = dataSeriesModel 
              Me.chart1.PrimaryXAxis.ValueType = ChartValueType.Category 
              Me.chart1.Series.Add(chartSeries) 
              Me.Controls.Add(buttonOk) 
              Me.Controls.Add(chart1) 
End Sub 
 
Private Sub ButtonOk_Click(ByVal sender As Object, ByVal e As EventArgs) 
              Dim dataSource As New BindingList(Of SalesData)() 
              dataSource.Add(New SalesData("2000", 13)) 
              Dim dataSeriesModel As New CategoryAxisDataBindModel(dataSource) 
              dataSeriesModel.CategoryName = "Mes" 
              dataSeriesModel.YNames = New String() { "Total" } 
              Me.chart1.Series(0).CategoryModel = dataSeriesModel 
              Me.chart1.Redraw(True) 
End Sub 
 
Screenshot: 
 
Before button click: 
 
 
After button click: 
 
 
 
 
 
If the above doesn’t meet your requirement, kindly revert us with more details about your requirement which will be helpful to give the best solution. 
  
Regards, 
Baby. 



RA Ricardo Abranches May 6, 2019 09:10 AM UTC

Hi Baby,
thanks for your help :-)



BP Baby Palanidurai Syncfusion Team May 6, 2019 09:17 AM UTC

Ricardo,

Most welcome. Kindly revert us, if you need further assistance. We are always happy in assisting you.


Regards,
Baby.

Loader.
Up arrow icon