更改图表标签中逗号的点图表c#

时间:2015-03-03 13:48:16

标签: c# charts numbers format

我必须更改图表标签的小数点分隔符。我不能像字符串一样直接放置它们,因为它们需要双倍才能制作图表。

以下是代码:

private static byte[] ObtenerBarraDoble(IList<ValorBarraDTO> valores)
    {
        var newColor1 = Color.FromArgb(187, 189, 191);
        var newColor2 = Color.FromArgb(0, 138, 209);
        using (var graficoPie = new Chart { Height = 200, Width = 700, RenderType = RenderType.BinaryStreaming })
        {
            var chartAreaPie = new ChartArea();
            //chartAreaPie.AxisX.LabelStyle.Format = "dd/MMM\nhh:mm";
            chartAreaPie.AxisX.MajorGrid.LineColor = Color.White;
            chartAreaPie.AxisY.MajorGrid.LineColor = Color.White;
            chartAreaPie.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8f);
            chartAreaPie.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8f);

            chartAreaPie.AxisX.LabelStyle.Format = "N0";
            chartAreaPie.AxisY.LabelStyle.Format = "N0";

            graficoPie.ChartAreas.Add(chartAreaPie);


            var serieNuevo = new Series("Cartera Actual")
            {
                ChartType = SeriesChartType.Column,
                XValueMember = "label",
                YValueMembers = "valor1",
                Color = newColor1,
                Legend = "Cartera Actual",
                IsValueShownAsLabel = true,
                LabelFormat = "N1",
                CustomProperties = "LabelStyle=Top"

            };

            graficoPie.Series.Add(serieNuevo);


            var serie = new Series("Cartera Recomendada")
            {
                ChartType = SeriesChartType.Column,
                XValueMember = "label",
                YValueMembers = "valor2",
                Color = newColor2,
                Legend = "Cartera Propuesta",
                IsValueShownAsLabel = true,
                LabelFormat = "N1",
                CustomProperties = "LabelStyle=Top"
            };


            graficoPie.Series.Add(serie);
            graficoPie.DataSource = valores;


            return PdfHelper.ChartABinario(graficoPie);
        }
    }

我想也许在CustomProperties中?我需要这样做,请帮助!

1 个答案:

答案 0 :(得分:0)

你能否告诉我你是否在使用XAML?关键是模板样式格式。这就是我做一些格式化的方法。如果它没有帮助,我为浪费你的时间而道歉。

<Style x:Key="SeriesColumn" TargetType="DVC:ColumnDataPoint">
    <Setter Property="Background" Value="{Binding BackColor}"></Setter>
    <Setter Property="Foreground" Value="{Binding ForeColor}"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DVC:ColumnDataPoint">
                <Grid>
                    <Rectangle
                                Fill="{TemplateBinding Background}"
                                Stroke="Black"
                                StrokeThickness="1"
                        />
                    <Grid
                                Background="Transparent"
                                Margin="{Binding SeriesMargin}"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Top">
                        <TextBlock
                            HorizontalAlignment="Center"
                            Background="Transparent" 
                            Foreground="{TemplateBinding Foreground}"
                            Text="{TemplateBinding FormattedDependentValue}"
                                    FontWeight="Bold"
                            FontSize="12"

                                    />
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

关键是模板和TetBlock。如果认为可以通过a。

进行足够深度的替换