使用asp.net图表附加自定义值

时间:2012-12-18 09:27:25

标签: asp.net-charts

我已经制作了一个asp.net图表,其中包含来自DB的x轴和y轴上的一些数据。

enter image description here

现在我想附加当前日的自定义值DEC这样的

enter image description here

请任何人告诉我如何才能实现这一目标。 Plz帮助! 这是我的图表代码

<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource11" Compression="5"
                                                BackImageAlignment="Top" Palette="None" Width="400px" Height="250px">
                                                <Series>
                                                    <asp:Series Name="2011-12" XValueMember="MON" YValueMembers="CRSH_11_12" ChartType="Spline"
                                                        YValuesPerPoint="2" IsXValueIndexed="True" MarkerSize="7" MarkerStyle="Square"
                                                        ChartArea="ChartArea1" LabelFormat="#,###,###" Color="Black" YValueType="Double"
                                                        Legend="Legend1" LegendToolTip="#TOTAL{#,###,###,###}">
                                                        <EmptyPointStyle LabelFormat="#,###,###" />
                                                    </asp:Series>
                                                    <asp:Series Name="2012-13" XValueMember="MON" YValueMembers="CRSH_12_13" ChartType="Spline"
                                                        YValuesPerPoint="2" IsXValueIndexed="True" MarkerSize="7" MarkerStyle="Diamond"
                                                        ChartArea="ChartArea1" LabelFormat="#,###,###" Color="0, 192, 0" YValueType="Double"
                                                        Legend="Legend1" LegendToolTip="#TOTAL{#,###,###,###}">
                                                        <EmptyPointStyle LabelFormat="#,###,###" />
                                                    </asp:Series>
                                                    <asp:Series Name="Target" XValueMember="MON" YValueMembers="CAN_TRG" ChartType="Spline"
                                                        YValuesPerPoint="2" IsXValueIndexed="True" MarkerSize="7" MarkerStyle="Triangle"
                                                        ChartArea="ChartArea1" LabelFormat="#,###,###" Color="Blue" YValueType="Double"
                                                        Legend="Legend1" LegendToolTip="#TOTAL{#,###,###,###}">
                                                        <EmptyPointStyle LabelFormat="#,###,###" />
                                                    </asp:Series>
                                                    <asp:Series Name="Todate" XValueMember="MON" YValueMembers="YTD_CRSH" ChartType="Spline" BorderWidth="1"
                                                        YValuesPerPoint="2" IsXValueIndexed="True" MarkerStyle="None"
                                                        ChartArea="ChartArea1" Color="Red" YValueType="Double"
                                                        Legend="Legend1" >

                                                    </asp:Series>
                                                </Series>
                                                <ChartAreas>
                                                    <asp:ChartArea Name="ChartArea1" AlignmentOrientation="All">
                                                        <AxisY Title="Crushing (MT)" TitleForeColor="3, 91, 172" TitleFont="Arial, 8.25pt">
                                                            <MajorGrid LineColor="217, 239, 253" />
                                                            <LabelStyle Format="#,###,###" />
                                                        </AxisY>
                                                        <AxisX LineColor="Maroon" TitleFont="Tahoma, 8pt" Title="Month" TitleForeColor="3, 91, 172">
                                                            <MajorGrid LineColor="217, 239, 253" />
                                                        </AxisX>
                                                    </asp:ChartArea>
                                                </ChartAreas>
                                                <Legends>
                                                    <asp:Legend Alignment="Far" Docking="Bottom" Name="Legend1">
                                                    </asp:Legend>
                                                </Legends>
                                                <Titles>
                                                    <asp:Title Font="Microsoft Sans Serif, 10pt, style=Bold" ForeColor="3, 91, 172" Name="Title1"
                                                        Text="Crushing">
                                                    </asp:Title>
                                                </Titles>
                                            </asp:Chart>

1 个答案:

答案 0 :(得分:0)

处理Customize控件的Chart事件。

private void chart1_Customize(object sender, EventArgs e)
{
    foreach (var xAxisLabel in chart1.ChartAreas[0].AxisX.CustomLabels)
    {
        if (// xAxisLabel is Dec)
            label.Text = xAxisLabel + /*custom day*/;
    }
}