Telerik Forums
UI for ASP.NET MVC Forum
2 answers
767 views
I know the chart component can export to PDF and/or an Image, but it saves the files via a URL, I imagine for including it in other pages or reports... Instead, what I'd like to do is offer the user to export the current chart to an image (or PDF), but then push that resulting image via a download for the user to download onto their local computer.  Any advice on how to accomplish this?
Nikolay
Telerik team
 answered on 22 Apr 2020
2 answers
44 views

I have 2 barcharts on a page, 1 showing monthly gross wages for a Year To Date, and a separate chart displaying the same thing, for the same period but for a year previously.  I'd like to hilight somehow, whether through a different bar color or bold facing both the common categories in both charts...  I hope that makes sense...  Let's trim it down..

 

First chart shows customer A, B, and C

Second chart shows customer B, D, E

Somehow or another, I'd like to draw the viewers attention that the same customer appears on both charts.  As I said, they are each different charts and data series' and completely unaware of each other.

<div class="chart">
    @(Html.Kendo().Chart<GWChartData>()
          .Name("chartPayrollYTD")
          .ChartArea(ca => ca.Height(600))
          .HtmlAttributes(new {@class = "center" })
          .Title("Top 10 Client Gross Wages - YTD (" + DateTime.Now.ToString("MMMM") + " " + DateTime.Now.Year + ")")
          .Legend(l => l.Position(ChartLegendPosition.Top))
          .Series(s =>
          {
              s.Column(m => m.GrossWages).Name("Gross Wages").Color("#009933").Labels(l => l.Visible(true).Position(ChartBarLabelsPosition.OutsideEnd).Format("C"));
          })
          .ValueAxis(va => va.Numeric().MinorGridLines(m => m.Visible(true)).Labels(l => l.Format("C")))
          .CategoryAxis(c => c.Categories(m => m.ClientId).Labels(l => l.Visible(true)))
          .DataSource(ds => ds
                .Read(r => r.Action("YTDGrossWages", "GWHReport", new {topNumber = 10}).Type(HttpVerbs.Get))
                .Events(ev =>
                {
                    ev.RequestEnd("requestEnd");
                    ev.RequestStart("requestStart");
                })
          )
          .Tooltip(tp => tp.Visible(true).Template("#=category# - #=dataItem.ClientName#: #=kendo.format('{0:C}', value)#"))
    )
</div>
 
<div class="chart">
    @(Html.Kendo().Chart<GWChartData>()
          .Name("chartPayrollLastYear")
          .ChartArea(ca => ca.Height(600))
          .HtmlAttributes(new {@class = "center" })
          .Title("Top 10 Client Gross Wages - YTD (" + DateTime.Now.ToString("MMMM") + " " + (DateTime.Now.Year - 1) + ")")
          .Legend(l => l.Position(ChartLegendPosition.Top))
          .Series(s =>
          {
              s.Column(m => m.GrossWages).Name("Gross Wages").Color("#009933").Labels(l => l.Visible(true).Position(ChartBarLabelsPosition.OutsideEnd).Format("C"));
          })
          .ValueAxis(va => va.Numeric().MinorGridLines(m => m.Visible(true)).Labels(l => l.Format("C")))
          .CategoryAxis(c => c.Categories(m => m.ClientId).Labels(l => l.Visible(true)))
          .DataSource(ds => ds
              .Read(r => r.Action("YTDGrossWages_LastYear", "GWHReport", new {topNumber = 10}).Type(HttpVerbs.Get))
              .Events(ev =>
              {
                  ev.RequestEnd("requestEnd");
                  ev.RequestStart("requestStart");
              })
          )
          .Tooltip(tp => tp.Visible(true).Template("#=category# - #=dataItem.ClientName#: #=kendo.format('{0:C}', value)#"))
          )
</div>
Joe
Top achievements
Rank 1
 answered on 20 Apr 2020
1 answer
60 views

I'm having a heck of a time building a line chart, showing what I want.

Here is the scenario: It is an MVC app, and I want to load a line chart with historical payroll data for each month, so along the bottom axis, there'd be a column for "Jan", "Feb", "Mar", "Apr", etc...  Along the side axis will be amounts.  Each column should be the value for the specific month.

There will be a variable number of line series for each year. A client may have values for 2017-2020, or values for 2014-2018.. SO the number of lines on the chart would be variable, but the columns are static...

I have attached an image of what the data looks like in a spreadsheet.  I am not building these series manually, they are coming from a database.  I just need some help with transforming the data as shown in the spreadsheet image into a collection that this damn line chart will accept, and plot how I want it to.

 

Joe
Top achievements
Rank 1
 answered on 17 Apr 2020
1 answer
575 views

     I have a column chart that I need to conditionally hide the tooltip based on a property of the model data that fills said chart.

public class chartModel
{
    public int ID { get; set; }
    public string Name {get; set;}
    public bool ShowTooltip { get; set; }
    public double FeesYTD { get; set; }
}

 

@(Html.Kendo().Chart<chartModel>()
               .Name("topFees")
               .ChartArea(chartArea => chartArea
                   .Background("transparent")
                   .Height(300)
               )
               .DataSource(ds => ds.Read(read => read.Action("FeeChartData", "PracticeAnalytics")))
               .SeriesDefaults(sd => sd.Column().Stack(false).Gap(.7).Overlay(ChartBarSeriesOverlay.None))
               .Series(series => series
                   .Column(model => model.FeesYTD)
               )
               .Tooltip(tooltip => tooltip
                   .Visible(true)
                   .Shared(true)
                   .SharedTemplate(
                       "# for (var i = 0; i < points.length; i++) { #" +
                           "# if (points[i].value !== 0) { #" +
                               "<div>#: points[i].series.Name# #: points[i].series.name# : #: kendo.format('{0:C}',points[i].value) #</div>" +
                           "# } #" +
                       "# } #"
                   )
               )
       )

 

Basically if the model.ShowToolTip is true then I want to show the tooltip, otherwise hide it.  Best I could find that is similar is using SharedTemplate, but I don't think I can access my model properties, only category and series.  So where in my example I have if (points[i].value != 0) I need something like if (model.ShowToopTip).

 

 

 

 

 

 

 

 

 

 

 
Alex Hajigeorgieva
Telerik team
 answered on 16 Apr 2020
5 answers
979 views

Hi,

I want to be able to hide the category axis on a line chart that doesn't have any data. Please see the attached; as you can see, there are a lot of dates in the middle that don't have any data as there isn't a point plotted, yet the date is still shown in the category axis and there is space reserved for it in the actual graph.

This looks untidy so we need to be able to hide all of the dates that don't have any data/a point. So for example anything from the 9th of July to the 19th of August should be completely hidden from the chart. How can we achieve this?

The current code:

<code>

Html.Kendo().Chart(Model.OutletColdTemperatures)
                .Name("OutletTemperatureMonitoringCold") // The name/ID.
                .ChartArea(chartArea => chartArea.Background("#ADD8E6")) // Background colour.
                .Title(title => title
                    .Text("Cold Temperatures") // Control the title at the top of the graph.
                    .Color("#2E5A78")
                    .Font("bold 24px Arial, Helvetica, sans-serif")
                    .Position(ChartTitlePosition.Top)
                )
                .DataSource(ds => ds
                    .Group(g => g.Add(d => d.SystemRef)) // This tells it to create a new/group each line by the System Ref.
                    .Sort(g => g.Add(d => d.SystemRef))
                )
                .SeriesDefaults(seriesDefaults => seriesDefaults
                    .Line().Style(ChartLineStyle.Smooth) // This controls the type of line shown.
                )
                .Series(series => series
                    .Line(value => value.Temp, date => date.Recorded) // This controls the line written out.
                    .Name("#: group.value #") // Control the value shown in the Key/Legend.
                    .Labels(labels => labels.Visible(false)) // Hide temperatures on the graph.
                    .MissingValues(ChartLineMissingValues.Interpolate) // Control how missing values are shown.
                )
                .CategoryAxis(axis => axis // This controls the category at the bottom. Currently shows the date.
                    .Title("Date")
                    .Type(ChartCategoryAxisType.Date)
                    .Categories(c => c.Recorded)
                    .Labels(labels => labels
                        .Rotation(-65) // Rotate the text around.
                        .Template("#: value.toLocaleDateString() #") // Format the date shown.
                    )
                )
                .ValueAxis(axis => axis // This controls the value at the left side. Currently shows the temperature.
                    .Numeric()
                    .Title("Temperature &deg;C")
                    .PlotBands(p => p
                        .Add(10, 10.2, "#FF0000")
                    )
                    .Max(20) // Set the maximum value shown at the top of the graph.
                )
                .Legend(legend => legend // This controls the Key/Legend. Currently shows the Outlet System Ref.
                    .Visible(false)
                    .Position(ChartLegendPosition.Bottom)
                    .Labels(x => x.Font(font: "9px Arial, Helvetica, sans-serif").Template("#: text #"))
                )
                .Tooltip(tooltip => tooltip // Add a tooltip showing the Outlet details.
                    .Visible(true)
                    .Template(tooltipTemplate)
                )
                .Events(events => events
                    .DataBound("OnDataBound_OutletTemperatureMonitoring")
                )

</code>

Any help would be appreciated. I think the same question has been answered here, however the response was a couple years ago: www.telerik.com/forums/hide-labels-on-date-axis-that-have-no-data#BFCuWHL3s0i8c7DX1uPcdw

Thanks

Alex Hajigeorgieva
Telerik team
 answered on 25 Mar 2020
6 answers
251 views

I would like to combine a stacked bar and line chart in the same graph. I am able to generate the stacked bars, however, I am having difficulties generating the line graph. The data for the chart is fed from the Model. Any help is appreciated.

Here is the "View"

01.@(Html.Kendo().Chart<MyModelName>()
02.                        .Name("MyChartName")
03.                        .AutoBind(true)
04.                        .Legend(legend => legend
05.                        .Visible(true)
06.                        )
07.                        .DataSource(ds => ds
08.                        .Read(read => read.Action("MyAction", "MyController"))
09.                        .Group(group => group.Add(model => model.Country))
10.                        )
11.                        .SeriesDefaults(seriesDefaults =>
12.                        seriesDefaults.Column().Stack(true)
13.                        )
14.                        .Series(series =>
15.                        {
16.                        series
17.                        .Column(model => model.ValueAmount)
18.                        .CategoryField("ValueYearMonth")
19.                        .Labels(labels => labels
20.                                .Visible(true)
21.                                .Background("transparent").Visible(true)
22.                                .Position(ChartBarLabelsPosition.OutsideEnd))
23.                        ;
24.                        series
25.                            .Line(model => <!!! NOT SURE HERE !!!>) //model.ValueAmount does not work
26.                        //.Line (new int[] { 35, 25, 50, -10, 15, 5, 35 })  //
27.                            .Color("#ff1c1c");
28. 
29.    })
30.                        .CategoryAxis(axis => axis
31.                        .Labels(label => label
32.                        .Position(ChartAxisLabelsPosition.Start)
33.                        )
34.                        .MajorGridLines(lines => lines.Visible(true))
35.                        .Line(line => line.Visible(false))
36.                        .Visible(true)
37.                        )
38.                        .ValueAxis(axis => axis.Numeric()
39.                        .MajorGridLines(lines => lines.Visible(false))
40.                        .Visible(true)
41.                        )
42.                        .Tooltip(tooltip => tooltip
43.                        .Visible(true)
44.                        )
45.                        .Events(events => events
46.                            .DataBound("onDataBoundStackedChart")
47.                        )
48.                    )

 

The Model:

01.public class MyModel
02.{
03.    public string Country { get; set; }
04.    public decimal ValueAmount { get; set; }
05.    public string Color { get; set; }
06.    public DateTime ValueDate { get; set; }
07.    public int ValueYearMonth { get; set; }
08.    public decimal GlobalValueAmountByMonth { get; set; }
09.}

 

And the Controller reads the data into the Model  and  "return Json(result);"

Thanks in advance,

Ricky

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Viktor Tachev
Telerik team
 answered on 12 Mar 2020
4 answers
186 views

Hallo,

I try the demo of Pie chart in my iphone, but it doesn't display correctly with the labels, some of the labels show only a small part, is it is a bugs or need some configuration in the code?, zie screenshot in attach.

Denitsa
Telerik team
 answered on 09 Mar 2020
4 answers
281 views

No errors but the chart is not showing.  The model has two "series" that are IEnumerable of objects that have properties for category, value and color.  The model is filled properly and if I don't try to use Ajax via DataSource / action and just load the object and set the Series it works fine.  Meaning I load an object <FlowsInOutChartData> inout in the top of a Razor page and then set the series via .Series(series => ... series.Donut(inout.InFlows) .Name("In Flows") etc. chart works fine.  Want to load via Ajax so the page comes back immediately (the chart takes a few seconds to load due to database calculation delay).

I think the problem is in the series func<>

series.Donut(d => d.InFlows, null)
               .Name("In Flows");

But not sure what I'm doing wrong.

 

@(Html.Kendo().Chart<WAPDBBusiness.Charts.FlowsInOutChartData>()
                                             .Name("chart")
                                             .ChartArea(chartArea => chartArea
                                                 .Background("transparent"))
                                             .Title(title => title
                                                 .Text("Cash Flows")
                                                 .Position(ChartTitlePosition.Bottom)
                                             )
                                             .Legend(legend => legend
                                                 .Visible(false)
                                             )
                                             .SeriesDefaults(series =>
                                                 series.Donut().StartAngle(150)
                                             )
                                              .DataSource(dataSource => dataSource
                                                                .Read(read => read.Action("CashInOutChartData", "PracticeAnalytics")) //Specify the action method and controller names.
                                            )
                                            .Series(series =>
                                                    {
                                                series.Donut(d => d.InFlows, null)
                                                      .Name("In Flows");
                                            })
                                            .Series(series =>
                                                    {
                                                series.Donut(d => d.OutFlows, null)
                                                      .Name("Out Flows");
                                            })
                   )

 

Controller:

public ActionResult CashInOutChartData()
 {
      var data = new WAPDBBusiness.Charts.CashFlowsInOutChart().GetFirmAnalyticsFlowsByQuarter(loginInfo.FirmID, 1, loginInfo.FirmID, true);

 

     return Json(data, JsonRequestBehavior.AllowGet);
 
 }

 

Model:

public class FlowsInOutChartData
    {
        public IEnumerable<FlowInOutChartItem> InFlows { get; set; }
        public IEnumerable<FlowInOutChartItem> OutFlows { get; set; }
    }
    public class FlowInOutChartItem
    {
        public int? myYear { get; set; }
        public int? myQtr { get; set; }
        public decimal Total { get; set; }
        public decimal PercentOfTotal { get; set; }
        /// <summary>
        /// Used by Telerik Donut Chart
        /// </summary>
        public string category
        {
            get
            {
                return "Q" + myQtr.ToString() + " " + myYear.ToString();
            }
        }
        /// <summary>
        /// Used by Telerik Donut Chart
        /// </summary>
        public decimal value
        {
            get
            {
                return PercentOfTotal;
            }
        }
        /// <summary>
        /// Used by Telerik Donut Chart
        /// </summary>
        public string color { get; set; }
      
    }

 

 

Abe
Top achievements
Rank 1
 answered on 27 Feb 2020
1 answer
49 views

When you hover over the legend it displays all the points for the series you are hovering over.  See attached image.  Is there a way to turn this off?

 

<div>
    <div id="chart">
 
        @(Html.Kendo().Chart<CashInvestedAreaChart>()
                .Name("chartCashInvested")
                .DataSource(ds => ds.Read(read => read.Action("CashInvestedChartData", "PracticeAnalytics")))
                .Transitions(false)
                .Theme("bootstrap")
                .Legend(l => l.Visible(true)
                        .Position(ChartLegendPosition.Bottom))
                .ChartArea(c => c.Margin(10, 8, 0, 10).Background("transparent").Height(280))
                .SeriesDefaults(s => s
                    .Area()
                    .Line(l => l.Style(ChartAreaStyle.Smooth))
                    .Stack(false))
                .CategoryAxis(axis => axis
                    .Categories(m => m.Date)
                    .Line(l => l.Visible(false))
                    .Labels(l => l.Visible(false))
                    .MajorGridLines(l => l.Visible(false))  
                    )
                .Tooltip(t => t.Visible(true).Template("#= series.name # <br /> #= kendo.toString(kendo.parseDate(category), 'MM/dd/yyyy') #: #= kendo.format('{0:C}', value) #"))
                .Series(series =>
                {
                    series.Area(model => model.MarketValue).Name("Market Value").Color("#60A7F5").Opacity(1);
                    series.Area(model => model.CashInvested).Name("Cash Invested").Color("#35608F").Opacity(1);
                })
                .ValueAxis(axis => axis
                    .Numeric()
                    .Labels(labels => labels.Template("#= ciFormatMillions(value) #" ) )
                    .AxisCrossingValue(-10)
                    .Line(line => line.Visible(false))
                )
                .Events(e => e.Render("scaleChart"))
        )
    </div>
Nikolay
Telerik team
 answered on 13 Jan 2020
1 answer
472 views

I have a set of data where for any given date, there is a number for each of five geographic regions. When I try to put this data in a pie chart, I get 5n different series in my pie chart, where n is the number of days of data. I just want the chart to add all the data for each region, no matter how many days, so that I just have five different series.

I've been scouring the documentation and forums for hours, but the only lead is Pie Chart Data Aggregates, which is only for the jQuery version of Kendo. I'm trying to get this to work for MVC, but the documentation for MVC Aggregates is completely unhelpful. How can I get the functionality I'm looking for?

Nikolay
Telerik team
 answered on 24 Dec 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?