2012-08-23 14 views
5

私は私がこれを行うことができ、.SetSeries内のデータは私の返されたデータがどうあるべきか、私のGetData()dotchart highcharts dllを使用してMVC3でHighChartを表示するにはどうすればよいですか?

.SetSeries(new Series 
    { 
     Type = ChartTypes.Pie, 
     Name = "Browser share", 
     Data = new Data(new object[] 
            { 
             new object[] { "Firefox", 45.0 }, 
             new object[] { "IE", 26.8 }, 
             new DotNet.Highcharts.Options.Point 
             { 
              Name = "Chrome", 
              Y = 12.8, 
              Sliced = true, 
              Selected = true 
             }, 
             new object[] { "Safari", 8.5 }, 
             new object[] { "Opera", 6.2 }, 
             new object[] { "Others", 0.7 } 
            }) 
     }); 
    } 

を交換したい円グラフ

Public ActionResult Charts 
    { 
     Highcharts chart = new Highcharts("chart") 
     .InitChart(new Chart { PlotShadow = false }) 
     .SetTitle(new Title { Text = "Browser market shares at a specific website, 2010" }) 
     .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" }) 
     .SetPlotOptions(new PlotOptions 
     { 
      Pie = new PlotOptionsPie 
      { 
       AllowPointSelect = true, 
       Cursor = Cursors.Pointer, 
       DataLabels = new PlotOptionsPieDataLabels 
       { 
        Color = ColorTranslator.FromHtml("#000000"), 
        ConnectorColor = ColorTranslator.FromHtml("#000000"), 
        Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" 
       } 
      } 
     }) 
     .SetSeries(new Series 
     { 
      Type = ChartTypes.Pie, 
      Name = "Browser share", 
      Data = new Data(new object[] 
            { 
             new object[] { "Firefox", 45.0 }, 
             new object[] { "IE", 26.8 }, 
             new DotNet.Highcharts.Options.Point 
             { 
              Name = "Chrome", 
              Y = 12.8, 
              Sliced = true, 
              Selected = true 
             }, 
             new object[] { "Safari", 8.5 }, 
             new object[] { "Opera", 6.2 }, 
             new object[] { "Others", 0.7 } 
            }) 
          }); 
     } 
    } 

    public JsonResult GetData() 
    { 
     int Param1; 
     Param1 = 1;  
     var reports = db.ExecuteStoreQuery<ResourceReports>("ResourceReports @EmployeeID", new SqlParameter("@EmployeeID", Param1)).ToList(); 
     return Json(reports, JsonRequestBehavior.AllowGet); 
    } 

にデータをバインドする方法をしようとしていますin GetData method

答えて

2

Dotnet.Highchartsを使用しているようです。 SeriesのリストとPointのリストを作成することができます。

List<Series> mySeries = new List<Series>(); 
List<Point> myPoints = new List<Point>(); 

私はあなたがそうのようなポイントデータを作成して生成する必要がある各シリーズをループします:

myPoints.Add(new Point { 
    X = (detailRec.RecordTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds, 
    Y = detailRec.TotalCount 
}); 

が次にあなたがそうのようなそのデータのためのポイントのリストを使用して、一連自体を作成することができます。

mySeries.Add(new Series{ 
    Name = distinctDistrict.Name, 
    Data = new Data(myPoints.ToArray()) 
}); 

その後、あなたは次の文を使用することができますシリーズを設定します

Visual Studioでオブジェクトブラウザを使用する場合、SeriesおよびPointクラスのその他のプロパティとメソッドが表示されます。上記のコードを使用するには、以下のusingステートメント含める必要があります:

using DotNet.Highcharts; 
using DotNet.Highcharts.Enums; 
using DotNet.Highcharts.Helpers; 
using DotNet.Highcharts.Options; 
using Point = DotNet.Highcharts.Options.Point; 
+0

@Tommmyジョンソンを.....私の質問は.SetSeriesあなたは '返すことはできません – SoftwareNerd

+3

GetDataメソッドの私の返されたデータでなければなりませんでしたSetSeries'のように、シリーズを設定するメソッドです。しかし、 'Series'オブジェクトを返すことができます。上の例では、 'mySeries'を返します。そして、 'SetSeries'メソッドでそれを使って系列をチャートに追加します。 –

関連する問題