0

我在我的 MVC 项目中使用 Devexpress 绘制饼图。

默认情况下,我的图表生成了三种颜色,如下所示

但是我的客户对它的颜色不满意,并希望我更改与我们的应用程序背景相匹配的颜色,所以请帮助我,如何做到这一点。

提前致谢。这是我的代码。

    settings.Name = "chart";
    settings.Width = 600;
    settings.Height = 250;
    settings.BorderOptions.Visible = false;

    Series series1 = new Series("Type", DevExpress.XtraCharts.ViewType.Pie3D);
    settings.Series.Add(series1);
    series1.ArgumentScaleType = ScaleType.Qualitative;
    series1.ArgumentDataMember = "ClassName";
    series1.ValueScaleType = ScaleType.Numerical;
    series1.ValueDataMembers.AddRange(new string[] { "PercentageValues" });


    series1.LegendPointOptions.PointView = PointView.ArgumentAndValues;
    series1.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
    series1.LegendPointOptions.ValueNumericOptions.Precision = 0;
    series1.Label.ResolveOverlappingMode = ResolveOverlappingMode.Default;
    series1.Label.Visible = false;
4

3 回答 3

3

请参考以下代码。我已经成功地实现了为范围栏提供自定义颜色的相同方法。我想它也适用于你的情况

 settings.CustomDrawSeriesPoint = (s, ev) =>
    {
        BarDrawOptions drawOptions = ev.SeriesDrawOptions as BarDrawOptions;

        if (drawOptions == null)
            return;

        Color colorInTarget = Color.Blue;
        double x = ev.SeriesPoint.Values[0];
        double y = ev.SeriesPoint.Values[1];


        if (x == 0)
        {  //Do starting
            colorInTarget = Color.FromArgb(159,125, 189);
        }
        else{
            //Red - price Increase
            // Green price Decrease
            if (y > previousYValue)
            {
                colorInTarget = Color.Red; ;
            }
            else
            {
                colorInTarget = Color.Green;
            }
        }


        previousYValue = y;

        drawOptions.Color = colorInTarget;
        drawOptions.FillStyle.FillMode = FillMode.Solid;
        drawOptions.Border.Color = Color.Transparent;



    };
于 2013-12-13T08:53:45.673 回答
0

您可以设置图表控件的主题和调色板属性。按照下面的链接查看 devexpress 文档。尽管这些示例指的是 winform 应用程序,但它们在 asp.net mvc 控件中仍然可用。

http://documentation.devexpress.com/#WindowsForms/CustomDocument7433 http://documentation.devexpress.com/#WindowsForms/CustomDocument5538

    // Define the chart's appearance and palette.
barChart.AppearanceName = "Dark";
barChart.PaletteName = "Opulent";
于 2013-07-27T18:20:24.440 回答
0
     private List<StudentClass.ChartsPointsSummary> GetStudentSummaryResults()
            {
                var StudentId = Convert.ToInt32(Request.Params["StudentID"]);

                var StudentDetailsP = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
                var Presents = StudentDetailsP.Select(p => new { p.Months, p.Presents});
                var CountsP = StudentDetailsP.Count();
                List<StudentClass.ChartsPointsSummary> MT = new List<StudentClass.ChartsPointsSummary>();
                foreach (var ab in Presents)
                {
                    MT.Add(new StudentClass.ChartsPointsSummary { PresentSummaryX = ab.Months, PresentSummaryY = Convert.ToInt32(ab.Presents) });
                }

                var StudentDetailsA = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
                var Absents = StudentDetailsP.Select(p => new { p.Months, p.Absents });
                var CountsA = StudentDetailsA.Count();
                foreach (var ab in Absents)
                {
                    MT.Add(new StudentClass.ChartsPointsSummary { AbsentSummaryX = ab.Months, AbsentSummaryY = Convert.ToInt32(ab.Absents) });
                }

                var StudentDetailsL = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
                var CountL = StudentDetailsL.Count();
                var Leaves = StudentDetailsP.Select(p => new { p.Months, p.Leaves });
                foreach (var ab in Leaves)
                {
                    MT.Add(new StudentClass.ChartsPointsSummary { LeaveSummaryX = ab.Months, LeaveSummaryY = Convert.ToInt32(ab.Leaves) });
                }
                return MT;
            }


@Html.DevExpress().Chart(settings =>
{

    settings.Name = "SummaryDetailsById";

    settings.Width = 1032;
    settings.Height = 250;

    Series chartSeries = new Series("Presents", DevExpress.XtraCharts.ViewType.Bar);
    chartSeries.ArgumentDataMember = "PresentSummaryX";
    chartSeries.ValueDataMembers[0] = "PresentSummaryY";
    settings.Series.Add(chartSeries);

    Series chartSeries2 = new Series("Absents", DevExpress.XtraCharts.ViewType.Bar);
    chartSeries2.ArgumentDataMember = "AbsentSummaryX";
    chartSeries2.ValueDataMembers[0] = "AbsentSummaryY";
    settings.Series.Add(chartSeries2);

    Series chartSeries3 = new Series("Leaves", DevExpress.XtraCharts.ViewType.Bar);
    chartSeries3.ArgumentDataMember = "LeaveSummaryX";
    chartSeries3.ValueDataMembers[0] = "LeaveSummaryY";
    settings.Series.Add(chartSeries3);

    settings.CrosshairEnabled = DefaultBoolean.Default;
    settings.BackColor = System.Drawing.Color.Transparent;
    settings.BorderOptions.Visibility = DefaultBoolean.True;

    settings.Titles.Add(new ChartTitle()
    {
        Text = "Student Attendance Summary"
    });

    XYDiagram diagram = ((XYDiagram)settings.Diagram);
    diagram.AxisX.Label.Angle = -30;
    diagram.AxisY.Interlaced = true;

}).Bind(Model).GetHtml()
于 2016-02-12T07:37:58.677 回答