BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
I am stuck, I am trying to create my first chart with the WinForms chart control. Stepping through the code I do not get any errors and the data seems to be there. However the chart does not render the data it remains blank.
Somewhere I am missing something this is my the code for my charting section. I am using VB.net. This is based on the sample of using code to bind the data.
This has to be something simple, so any suggestions as to what I have missed?
BindingSource1.DataSource = dsChartData
modChart = New ChartDataBindModel(BindingSource1)
modChart.XName = "Date"
modChart.YNames = New String() {"Price"}
Dim series As New ChartSeries("Import Data")
series.Text = series.Name
series.SeriesModel = modChart
series.Style.TextColor = Color.Black
series.Style.Font.Bold = True
xAxisLableModel.LabelName = "Date"
ChartControl1.PrimaryXAxis.LabelsImpl = xAxisLableModel
ChartControl1.PrimaryYAxis.ValueType = ChartValueType.Custom
Hello John Willems,
We have validated your query and would like to inform you that we suspect that in the ChartDataBindModel argument you have passed a Class object instead of the data source collection. Therefore, please use the code snippet below to achieve your requirement by passing data collection as argument.
Dim dataSource As BindingList(Of SalesData) = New BindingList(Of SalesData) dataSource.Add(New SalesData("1999", 3)) dataSource.Add(New SalesData("2000", 7)) dataSource.Add(New SalesData("2001", 12)) dataSource.Add(New SalesData("2002", 18)) dataSource.Add(New SalesData("2003", 22)) dataSource.Add(New SalesData("2004", 30)) dataSource.Add(New SalesData("2005", 40)) dataSource.Add(New SalesData("2006", 50)) dataSource.Add(New SalesData("2007", 65)) dataSource.Add(New SalesData("2008", 75))
Dim dataSeriesModel As ChartDataBindModel = New ChartDataBindModel(dataSource) dataSeriesModel.XName = "Year" dataSeriesModel.YNames = New String() {"Sales"} |
I have attached a demo sample and UG link for more reference. Please check and let us know if you need any more assistance.
Regards,
Moneeshram.
Thank you so much for the help. It helped me find the error in my code. I was not actually loading the data into the model. Now I need to get into the details.
Now three quick followup questions. I doing all of this in VB and code behind.
We have validated all your query and would like to suggest following solutions,
Query 1: My data lables are not showing, how do I set them in code?
We can achieve this by setting the DisplayText property to true in the Series.Style property and you have to enable it for each series, as shown in the code snippet below. Also refer the attached ug links for more information.
ChartSeries1.Style.DisplayText = True |
UG Link: https://help.syncfusion.com/windowsforms/chart/chart-series#displaytext
Query 2: I need to add a trend line to my ScatterPlot how is that done in code?
We can achieve this by creating a trend line and setting it to the ChartSeries.Trendline property as shown in the code snippet below, and refer the attached UG link for more information.
trendline = New Trendline() 'Customizing the Trendline trendline.Name = "Linear" trendline.Visible = True trendline.Style = DashStyle.Solid trendline.Width = 2.0F trendline.Color = Color.Black trendline.Type = TrendlineType.Linear 'Adding Trendline to the series ChartSeries1.Trendlines.Add(trendline) |
UG Link: https://help.syncfusion.com/windowsforms/chart/chart-series?cs-save-lang=1&cs-lang=vb#trendlines
Query 3: I need to use the Slope calculation I have not seen an example of loading the x and y values from my dataset. Is that possible and is there an example?
We can't seem to understand whether you need to calculate the slope of the trendline or any other data values. Could you please share more details about which series or data values you want to calculate the slope of? This will help us find a better solution quickly.
Regards,
Moneeshram.
Thank you! The information was very helpful. I admit Charts confound me. I have never built a custom chart before.
I thought if I provided a more complete explanation it might help.
The app I am building is a utility type application. It needs to be able to handle up to 100 datapoints. The data considers of a price and a date. The chart should show the price in a scatter plot. The data should move left to right based on date. The earliest date on the left and later dates. Vertically it should show the price.
The app need a trend line that shows slope and a 3rd Order Polynominal trendline based on the same data.
The app also need to perform a Slope calc and that same data and display that result to the user.
The app needs to be able refresh the data and the graph as the user changes data selection. I believe I can work this out.
All of this unbound and done in code behind page in the Winforms app using VB.net. I have attached at text file containing the current charting code I am unsing.
As you can tell I have a 'mess'.
I realized I need to do a calculation with the date. I have done that and the chart is now using Days and Adjusted Price. I am not sure I have the x&y axis correctly set. See Image
What is 'Forward Forecast' and 'Backward ForeCast?
I still need to sort out the Scope formula so I use that value as a multiplier for Days. I need the result to show in Adjustment Rate. I see something called m_scope in the objects.
We have validated your query and you can achieve your expected chart view by setting the proper Axis value types and proper XName and YNames based on the axis types, as shown in the snippet below.
Me.ChartControl1.PrimaryXAxis.ValueType = ChartValueType.DateTime Me.ChartControl1.PrimaryYAxis.ValueType = ChartValueType.Double
Dim dataSeriesModel As ChartDataBindModel = New ChartDataBindModel(dataSource) dataSeriesModel.XName = "F2" dataSeriesModel.YNames = New String() {"F3"} |
Also, the forward and backward forecasting shows future
and past trends based on the given data values. Here, we have attached two
trend lines.
We have set forward forecast as 10 and a backward forecast as 5, so the first
trend line will show the next 10 possible trends and the second trend line will
show the past 5 trends based on the data. The slope is calculated automatically
based on forecast value.
trndLne.ForwardForecast = 10 polyTrend.BackwardForecast = 5 |
Please refer the attached UG document and sample for more information. And let us know you need further assistance.
UG Link:
https://help.syncfusion.com/windowsforms/chart/chart-series#forward-forecasting
https://help.syncfusion.com/windowsforms/chart/chart-series#backward-forecasting
https://help.syncfusion.com/windowsforms/chart/chart-axes#axis-value-type
Regards,
Moneeshram.
Thank you for you continued patience and support. It is a bit embarrassing to have to ask what I am sure for most are simple questions.
This is something of importance to my customer.
I still need to sort out the Scope formula so I use that value as a multiplier for Days. I need the result to show in Adjustment Rate. I see something called m_scope in the objects. I alse see a Calculate Engine formula for slope.
I would like to pass the values of from the datasource as x & y for the calc.
Thanks again for all the help,
John W
We would like to inform you that we are using a trendline
generic formula in our source to calculate the slope values.
And we described the formula steps below, please find it.
slope = (NΣXY - ΣXΣY) / (NΣX^2 - (ΣX)^2) |
where N is the number of data points, ΣXY is the sum of the products of x and y for each data point, ΣX is the sum of x values, ΣY is the sum of y values, and ΣX^2 is the sum of the squares of x values.
For example, we have:
N = 4 ΣX = 10 ΣY = 57 ΣXY = 379 ΣX^2 = 30 |
Substituting these values in the formula, we get:
slope = (4*379 - 10*57) / (4*30 - 10^2) = 7.8 |
The y-intercept of the line can be calculated using the formula:
y-intercept = (ΣY - slope*ΣX) / N |
Substituting the values, we get:
y-intercept = (57 - 7.8*10) / 4 = 3.25 |
Therefore, the linear trendline equation for the given data is:
y = 7.8x + 3.25 |
This equation can be used to predict the y value for any given x value within the range of the data based on your requirements.
Regards,
Moneeshram.