ComponentOne
Web API Explorer ASP.NET Web API Explorer

MVCFlexChart

Labels

This sample demonstrates how to export a MVC FlexChart with different labels to image file.

Features

MarchAprilMayOrangesApplesPearsBananasPineapples04435247243443535

Settings

Export
Export Format : Height :
Width :
Export Name :

Description

This sample demonstrates how to export a MVC FlexChart with different labels to image file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using C1.Web.Mvc.Chart;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApiExplorer.Models;
 
namespace WebApiExplorer.Controllers
{
    public partial class MVCFlexChartController : Controller
    {
        private static IDictionary<string, object[]> CreateLabelSettings()
        {
            var settings = new Dictionary<string, object[]>
            {
                {"ChartType", new object[]{"Column", "Bar", "Scatter", "Line", "LineSymbols", "Area", "Spline", "SplineSymbols", "SplineArea"}},
                {"DataLabel.Position", new object[]{LabelPosition.Top, LabelPosition.Right, LabelPosition.Bottom, LabelPosition.Left, LabelPosition.None}},
                {"DataLabel.Border", new object[]{false, true}},
            };
 
            return settings;
        }
 
        public ActionResult Labels()
        {
            var model = new ClientSettingsModel
            {
                Settings = CreateLabelSettings()
            };
            ViewBag.Options = _flexChartModel;
            return View(model);
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@model ClientSettingsModel
@{
    ViewBag.DemoSettings = true;
    ImageExportOptions optionsModel = ViewBag.Options;
    ViewBag.DemoSettingsModel = Model;
    IEnumerable<Fruit> fruits = Fruit.GetFruitsSales();
}
 
@(Html.C1().FlexChart().Id(optionsModel.ControlId).Bind("Name", fruits).Series(sers =>
{
    sers.Add().Binding("MarPrice").Name("March");
    sers.Add().Binding("AprPrice").Name("April");
    sers.Add().Binding("MayPrice").Name("May");
}).DataLabel(dl => dl.Position(C1.Web.Mvc.Chart.LabelPosition.Top).Content("{y}")))
 
@section Settings{
    @Html.Partial("_ImageExportOptions", optionsModel)
}
 
@section Description{
    @Html.Raw(Resources.MVCFlexChart.Labels_Text0)
}