Asp.net图表,如何将X轴标签位置设置为左对齐而不是居中?

时间:2015-01-02 01:31:55

标签: c# css asp.net charts histogram

我花了好几个小时试图解决这个愚蠢的问题。我用asp图表控件创建一个直方图。我想要做的就是在列的左侧有xaxis标签,而不是在它的中心。 Xaxis lable似乎没有像系列那样的位置属性,所以我无法弄清楚它是否令人沮丧。

这是我正在谈论的图形类型的示例代码,以向您展示我的内容:

        private void Graphique()
    {
        // Creating the series 
        Series series2 = new Series("Series2");

        // Setting the Chart Types
        series2.ChartType = SeriesChartType.Column;

        // Adding some points
        series2.Points.AddXY(1492, 12);
        series2.Points.AddXY(2984, 0);
        series2.Points.AddXY(4476, 1);
        series2.Points.AddXY(5968, 2);
        series2.Points.AddXY(7460, 2);
        series2.Points.AddXY(8952, 12);
        series2.Points.AddXY(10444, 4);
        series2.Points.AddXY(11936, 3);
        series2.Points.AddXY(13428, 3);
        series2.Points.AddXY(14920, 5);
        series2.Points.AddXY(16412, 1);

        Chart3.Series.Add(series2);

        Chart3.Width = 600;
        Chart3.Height = 600;

        // Series visual
        series2.YValueMembers = "Frequency";
        series2.XValueMember = "RoundedValue";
        series2.BorderWidth = 1;
        series2.ShadowOffset = 0;
        series2.IsXValueIndexed = true;

        // Setting the X Axis
        Chart3.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true;
        Chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1;
        Chart3.ChartAreas["ChartArea1"].AxisX.Maximum = Double.NaN;
        Chart3.ChartAreas["ChartArea1"].AxisX.Title = "kbps";

        // Setting the Y Axis
        Chart3.ChartAreas["ChartArea1"].AxisY.Interval = 2;
        Chart3.ChartAreas["ChartArea1"].AxisY.Maximum = Double.NaN;
        Chart3.ChartAreas["ChartArea1"].AxisY.Title = "Frequency";
    }

现在我的真实图表如下所示,Actual result

我想要与此网站类似的内容: Desired layout chart

你看,x标签位于左侧,考虑到直方图的每一列代表一系列值的频率,这更有意义.......

任何帮助将不胜感激......

1 个答案:

答案 0 :(得分:0)

您是否尝试添加CustomLabels来替换默认值?例如:

for (int i = 0; i <= 10; i++) {
    area.AxisX.CustomLabels.Add(i + 0.5, i + 1.5, i, 0, LabelMarkStyle.None);
}

前两个用于定位,第三个用于标签的文本值。