This is a migrated thread and some comments may be shown as answers.

Programmatic Creation of Series and Data

8 Answers 788 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 27 Jun 2013, 01:35 PM
hi

i am having an issue with the programmatic creation of series and data , i have many series to add to a line chart , but the data is based on a time series so i am struggling to get it properly into a system.

would anyone be able to provide an example of programmatic creation of multiple series data based on a time series ?

Peter.

8 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 02 Jul 2013, 08:10 AM
Hello Peter,

Numerical SeriesItems that consists DateTime data cannot be created programmatically in RadHtmlChart, because their x/y values are of type decimal. The exception is the categorical series, which accept strings for their X-Axis labels.

The chart, however, can be databound to DateTime objects, so that instead of creating series items programmatically you can created a sample datasource which can be bound to the chart. For example:
ASPX:
<telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Width="600px" Height="400px">
</telerik:RadHtmlChart>
C#:
protected void Page_Load(object sender, EventArgs e)
{
  
    DataTable dt = new DataTable();
    dt.Columns.Add("id");
    dt.Columns.Add("xValues");
    dt.Columns.Add("yValues");
    for (int i = 0; i < 5; i++)
    {
        dt.Rows.Add(i, (10 + i).ToString() + " Apr", 20 + i);
    }
  
    ScatterLineSeries sls1 = new ScatterLineSeries();
    sls1.LabelsAppearance.DataFormatString = "{0:d}";
    sls1.DataFieldX = "xValues";
    sls1.DataFieldY = "yValues";
  
    RadHtmlChart1.PlotArea.Series.Add(sls1);
    RadHtmlChart1.DataSource = dt;
    RadHtmlChart1.DataBind();
  
}


Regards,
Danail Vasilev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Peter
Top achievements
Rank 1
answered on 02 Jul 2013, 08:17 AM
ok then

if thats the case how do i bind multiple series of data to the radhtmlchart ?

in one of your examples you are doing it by columns in a datatable so there are no true datasets in your examples.

i have 2 options , i have a 3 column table , which is basically series , datetime , value how would i bind multiple series in that instance ?

the other is i have a dataset with multiple tables each with a datetime and values where the tables represent each series , how would this be bound ?

Peter.
0
Lidiya
Top achievements
Rank 1
answered on 03 Jul 2013, 01:41 AM
Hi All,

I need to display Order Date in X Axis, Total Order Quantity in Y Axis...and in each Order Date there may be 1 or more customers (Series Names)...ie, total order made by customers on that particular date. I need to implement this in RadHtmlChart stacked Column Chart.

Please see the attached image similar to my requirement.

Regards,
Seena
0
Danail Vasilev
Telerik team
answered on 03 Jul 2013, 02:54 PM
Hello Peter,

RadHtmlChart can be bound to only one datasource which must contain all the data for its series/xaxis labels in separate fields/columns. If you have a dataset with multiple datatables, then you must merge these tables into one table, so that it can be bound to the chart.

Regarding your first question I am sorry to say that a grouping functionality of the chart is not supported, so that you cannot achieve that out of the box. Such a feature request, however, has already been logged as a PITS item here, so that you can monitor, comment or raise its priority by voting on it. For the time being you can manually do the grouping manipulations of the datasource. An example illustrating that can be found in this forum thread.

Regarding the Seena's question it has already been asked in this forum thread, so we can continue our discussion there.

Regards,
Danail Vasilev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Mike
Top achievements
Rank 1
answered on 08 Aug 2015, 11:24 AM

But can be mixed: databinded series with those created programmatically, for example to show dotted cut line?

If possible, if we know that x-avis is datetime & we know the amount of rows in DataTable - we can create & add to serie the same amount of LineSeriesItems and after add theseria after DataBind() method.

0
Danail Vasilev
Telerik team
answered on 11 Aug 2015, 11:54 AM
Hi Mike,

I have already replied to the other forum post that was opened by you on the matter here (http://www.telerik.com/forums/is-it-possible-plot-two-different-series-in-one-chart), so that we can continue our discussion there.

Could I also ask you when you have technical questions to use the corresponding channels for that - either open a support ticket which requires a subscription or ask the community in the forum? I refer here the code library which was opened on this regard too.

Thank you for your cooperation.

Regards,
Danail Vasilev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Hans
Top achievements
Rank 1
answered on 26 Jul 2018, 06:24 PM
I try to learn how to add series and data programmatically.  It seems to me this example cannot work properly with current version of Telerik Assemblies.  Can you provide an correct example?  I am using 2018.2.710.45.  Thank you.
0
Vessy
Telerik team
answered on 30 Jul 2018, 03:57 PM
Hi Hans,

The following help article explains (and demonstrates) the different ways in which RadHtmlChart can be created ( declaratively, using data binding, or programmatically):
https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/data-binding/setting-explicit-items

You can find more samples showing programmatically created chart series in this help article:
https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/how-to/programmatic-creation-of-seriesitems-with-datetime
and this live demo:
https://demos.telerik.com/aspnet-ajax/htmlchart/examples/serversideapi/programmaticcreation/defaultcs.aspx

Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Chart (HTML5)
Asked by
Peter
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Peter
Top achievements
Rank 1
Lidiya
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Hans
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or