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

Hover Series Labels and formatting Category Lables (MVC)

3 Answers 321 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 2
Ian asked on 19 Jul 2013, 09:26 PM
My chart looks fairly good. 2 questions though. (See attached screen shot)

1) How can I make the Series labels only appear when the mouse hovers?
2) How do I format the Category Axis (Date) to "MMM d". My attempt below doesn't do anything to the date displayed.

Html.Kendo().Chart<AccountPerformance>(Model.Results)
    .Name("chart")
    .Title("Market Value")
    .Legend(legend => legend.Visible(false))
    .Series(series =>
            series.Line(model => model.Metrics.MarketValue)
                    .Name(Model.ColumnTitle)
                    .Labels(false)
    )
    .ValueAxis(axis => axis.Numeric()
        .Labels(labels => labels.Format("{0:C0}")))
    .CategoryAxis(axis => axis
        .Categories(model => model.ObservationDate)
        .Labels(labels =>
            {
                labels.Format("MMM d");
                labels.Rotation(45);
            } ))
    .Render();


3 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 22 Jul 2013, 10:12 AM
Hello Ian,

Up to your questions:

  1. I am afraid this is not supported by Kendo UI Chart, however you may consider using a tooltip (as shown in this online demo);
  2. In order to achieve this you could use the following format
    //....
    .CategoryAxis(axis => axis
        //....
        .Labels(l=>l.Format("MMMM/dd"))
    )
Regards,
Iliana Nikolova
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ian
Top achievements
Rank 2
answered on 22 Jul 2013, 05:31 PM
Hi lliana,

Unfortunately formatting the horizontal dates to MMM d didn't make any change in the display .

You can see from the newly attached screenshot that the dates appear crunched as "1/31/2013 12:00:00 AM" instead of "JAN 31"

Here's my full chart:

@{
    Html.Kendo().Chart<AccountPerformance>(Model.Results)
        .Name("chartMKT")
        .Title("Market Value")
        .Legend(legend => legend.Visible(false))
        .Series(series =>
                series.Line(model => model.Metrics.MarketValue)
                      .Name(Model.ColumnTitle)
                      .Labels(false)
        )
        .ValueAxis(axis => axis.Numeric()
                               .Labels(labels => labels.Format("{0:C0}")))
        .CategoryAxis(axis => axis
                                  .Categories(model => model.ObservationDate)
                                  .Labels(labels => labels.Format("MMMM/dd"))
                                  )
        .SeriesDefaults(builder => builder.Line().Color("#005984"))
        .Tooltip(tooltip => tooltip
              .Visible(true)
              .Format("{0:C}")
              .Color("white")
              .Background("black")
              .Template("#= value #")
        )
         .Render();
}
0
Accepted
Ian
Top achievements
Rank 2
answered on 22 Jul 2013, 05:51 PM
I found a solution. You need to add .Date() to the CategoryAxis to have the value format correctly:

.CategoryAxis(axis => axis
    .Date()
Tags
Charts
Asked by
Ian
Top achievements
Rank 2
Answers by
Iliana Dyankova
Telerik team
Ian
Top achievements
Rank 2
Share this question
or