使用linq绑定图表

时间:2013-11-27 06:26:34

标签: c# asp.net linq charts

我使用c#

在asp.net的Visual Studio 12中编码

我遇到了将linq查询绑定到图表的麻烦。 linq查询生成正确的输出。但代码给了我一个格式异常。

这是我的代码的链接,有些人可以帮帮我。我不知道出了什么问题,为什么数据不会显示在图表上。

linq包含有关代码的所有信息。

Unable to produce a chart using linq in csharp

1 个答案:

答案 0 :(得分:1)

#region ChartDataBinding
    //This method binds the chart to a given datasource.
    private void BindChart(object populations)
    {
        this.ChartWebControl1.Series.Clear();

        ChartSeries series = new ChartSeries("Populations");
        ChartDataBindModel dataSeriesModel = new ChartDataBindModel(populations);

        // If ChartDataBindModel.XName is empty or null, X value is index of point.
        dataSeriesModel.YNames = new string[] { "Population" };

        series.SeriesModel = dataSeriesModel;

        // ChartDataBindModel implements the IChartSeriesIndexedModel interface also.
        // series.SeriesIndexedModelImpl = dataModel;

        ChartDataBindAxisLabelModel dataLabelsModel = new ChartDataBindAxisLabelModel(populations);

        dataLabelsModel.LabelName = "City";

        ChartWebControl1.Series.Add(series);
        ChartWebControl1.PrimaryXAxis.LabelsImpl = dataLabelsModel;

        ChartWebControl1.PrimaryXAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode;
        ChartWebControl1.PrimaryXAxis.LabelIntersectAction = ChartLabelIntersectAction.MultipleRows;

        ChartWebControl1.PrimaryXAxis.Title = "City";
        ChartWebControl1.PrimaryYAxis.Title = "Population (Million)";
        SeriesStyles();
    }
    #endregion

链接:

http://asp.syncfusion.com/demos/ui/chart/Data%20Binding/LINQDataSource/CS/linqdatasource.aspx