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

Chart Serie Dynamic Source

1 Answer 83 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Wenzl
Top achievements
Rank 1
Wenzl asked on 12 Apr 2017, 11:56 AM

Hello ,

i am working on a chartingtool with variable datasources and more than one chart.

 

in my model i have a object[] which contains the chartdata for the charts.

this model has an array of List<ChartDataSerie>[] which contains the data for every series.

ChartDataSerieModel:

01.public class ChartDataSerie
02.   {
03.       public ChartDataSerie(string description, double value)
04.       {
05.           Description = description;
06.           Value = value;
07.       }
08.       public ChartDataSerie(string description, double value, string color, double opacity)
09.       {
10.           Description = description;
11.           Value = value;
12.           Color = color;
13.           Opacity = opacity;
14.       }
15. 
16.       public string Description { get; set; }
17.       public Double Value { get; set; }
18.       public string Color { get; set; }
19.       public double Opacity { get; set; }
20.   }

 

 

Now i want to bind a serie to a List<ChartSeriesData>, Value contains the Data, Description contains the Category

  1. each object contains an chart in Model.Kennzahlen, for to create a chart for every object in Model.Kennzahlen
  2. want to create an serie for every object in Model.Kennzahlen[i].Series
  3. Value are always a double, and Description (Category) the same at every Series ( Date in string)
01.@for (int i = 0; i < Model.Kennzahlen.Count; i++)
02.        {
03.               <div class="col-lg-3">
04.                <div class="ibox float-e-margins">
05.                    <div class="ibox-title">
06.                        <h5>Chart 1</h5>
07.                    </div>
08.                    <div class="ibox-content">
09.                        <div>
10.                            @(Html.Kendo().Chart(Model.Kennzahlen[i].Series)
11.                                .Name("chart" + i)
12.                                .Legend(legend => legend
13.                                    .Visible(false)
14.                                    .Position(ChartLegendPosition.Bottom)
15.                                )
16.                                .ChartArea(chartArea => chartArea
17.                                    .Background("transparent")
18.                                    .Height(200)
19.                                )
20.                                .Series(series =>
21.                                {
22.                                    for (int x = 0; x < Model.Kennzahlen[i].Series.Length; x++)
23.                                    {
24.                                        series.Column(Model.Kennzahlen[i].Series[x]);
25.                                    }
26.                                })
27.                                .CategoryAxis(axis => axis
28.                                    .Categories(model => model[0].Description)
29.                                    .MajorGridLines(lines => lines.Visible(false))
30.                                    .Line(line => line.Visible(false))
31.                                )
32.                                .ValueAxis(axis => axis.Numeric()
33.                                    .Max(28)
34.                                    .MajorGridLines(lines => lines.Visible(false))
35.                                    .Visible(false)
36.                                )
37.                                .Tooltip(tooltip => tooltip
38.                                    .Visible(true)
39.                                    .Format("{0}%")
40.                                    .Template("#= series.name #: #= value #")
41.                                )
42.                                )
43. 
44.                        </div>
45.                    </div>
46.                </div>
47.            </div>
48.        }

 

How can i solve this ?

 

Thank you in advance and hope it is understandable for you :)

 

 

 

Thank you in advance
Thank you in advance

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 17 Apr 2017, 05:17 AM
Hi Wenzi,

There should be no problems creating the Chart dynamically and settings its Series and CategoryAxis, but the only issue that I see is that the Value should be a double[]:
series.Column(new double[] { 56000, 63000, 74000, 91000, 117000, 138000 }).Name("Total Visits").Color("#a0b0c0");

Please modify the code accordingly and try passing the array with the data and see if that will resolve the problems that you are facing.

Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Charts
Asked by
Wenzl
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or