如何允许用户创建任意数量的字符串

时间:2015-11-28 19:10:48

标签: asp.net-mvc asp.net-mvc-5

我是ASP.NET的新手。我正在创建一个允许用户创建图表的简单网站。在前端我使用的是Charts.js,其中每个图表的数据如下所示:

var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        }
    ]
};

我的计划是为图表创建一个数据模型,允许用户指定图表的各种属性。以下是我的模特:

以下是我的课程。假设每个图表现在只有一个数据集:

public class Chart
{
    public int ID { get; set; }
    public string title { get; set; }
    public string fillColor { get; set; }
    public string strokeColor { get; set; }
    public string pointColor { get; set; }
}

我的问题是,处理label属性的最佳方法是什么?我是否应该将它作为另一个字符串属性包含在类中,让用户将每个标签输入到以分号分隔的输入框中,然后遍历它以填充JavaScript对象上的labels属性?或者有更好的方法吗?

注意:我并不担心图表上的data整数数组。它的所有起始值都是0,因此我将对其进行硬编码。

1 个答案:

答案 0 :(得分:1)

我更愿意保留下面的模型。

   public class Dataset
    {
        public string label { get; set; }
        public string fillColor { get; set; }
        public string strokeColor { get; set; }
        public string pointColor { get; set; }
        public string pointStrokeColor { get; set; }
        public string pointHighlightFill { get; set; }
        public string pointHighlightStroke { get; set; }
        public List<int> data { get; set; }
    }

    public class Chart
    {
        public List<string> labels { get; set; }
        public List<Dataset> datasets { get; set; }
    }
相关问题