asp.net c# how to use custom colours in charts

孤人 提交于 2020-03-26 03:33:33

问题


can any one show me I might be able to use custom colours in an ASP.Net chart control. so for example I have two series TOTAL and TARGET and I want to set the colour for total to green and the colour for target to be red .


回答1:


Something like this:

Color[] colors = new Color[] { Color.Green, Color.Red };
foreach (Series series in Chart1.Series)
{
    foreach (DataPoint point in series.Points)
    {
        point.LabelBackColor = colors[series.Points.IndexOf(point)];
    }
}



回答2:


iv done something like

    Chart2.Series.Add(new Series("Target")
    {
        ChartType = SeriesChartType.Column,
        Color = Color.Red,
    });



回答3:


suppose that you have two points for your Series1. So you can customise the colors as follow:

Chart1.Series["Series1"].Points[0].Color=Color.Red;
Chart1.Series["Series1"].Points[1].Color=Color.Yellow;



回答4:


The System.Web.UI.DataVisualization.Charting.Series object has a Color property. Simply set the color property to what you need it to be. Here follows a code sample that adds a horizontal line of a given value to a chart:

public static System.Web.UI.DataVisualization.Charting.Chart addLineToChart(
    System.Web.UI.DataVisualization.Charting.Chart pChart, double pValue, System.Drawing.Color pColor)
{        
    // I will declare a new series where every value is the value passed in
    System.Web.UI.DataVisualization.Charting.Series constantLineSeries = new System.Web.UI.DataVisualization.Charting.Series();
    constantLineSeries.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
    constantLineSeries.BorderWidth = ChartingValues.CHART_LINE_THICKNESS;
    constantLineSeries.Color = pColor;
    // At each point in the old series, add a constant point in the new series.
    foreach(System.Web.UI.DataVisualization.Charting.DataPoint point in pChart.Series[0].Points)
    {
        System.Web.UI.DataVisualization.Charting.DataPoint constantLinePoint = new System.Web.UI.DataVisualization.Charting.DataPoint();
        constantLinePoint.XValue = point.XValue;            
        constantLinePoint.YValues = new double[] { pValue };
        constantLineSeries.Points.Add(constantLinePoint);
    }
    pChart.Series.Add(constantLineSeries);
    pChart.ChartAreas[0].Area3DStyle.Enable3D = false;

    return pChart;
}

This code sample makes adjustments to some other properties you will likely find useful as well.




回答5:


I don't know if this will help, but I created a Custom Control that exposes several parameters that you can adjust, such as chart type, color, wall width, etc.

http://www.foliotek.com/devblog/asp-net-4-0-custom-chart-control-adjustable/



来源:https://stackoverflow.com/questions/6440658/asp-net-c-sharp-how-to-use-custom-colours-in-charts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!