ComponentOne
Web API Explorer ASP.NET Web API Explorer

MVCFlexChart

Labels

Features

Settings

Export
Export Format :
Height :
Width :
Export Name :

Description

This sample demonstrates how to export a MVC FlexChart with different labels to image file.
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);
        }
    }
}
@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)
}