Пользовательские метки осей visifire не отображаются

Мне нужно экспортировать мою диаграмму как изображение, не показывая ее сначала в WPF. Итак, я построил диаграмму в коде:

    public void CreateHistogram(CalcRepository cr, int i)
    {
        Chart chart = new Chart();

        chart.Width = 300;
        chart.Height = 200;
        chart.ScrollingEnabled = false;
        chart.AnimationEnabled = false;
        chart.TrendLines.Add(new TrendLine{Value = cr.Mean,Orientation = System.Windows.Controls.Orientation.Vertical});
        chart.TrendLines.Add(new TrendLine{Value = cr.ChartTrippleNegativeStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});chart.TrendLines.Add(new TrendLine{Value = cr.ChartTripplePositiveStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});
        chart.TrendLines.Add(new TrendLine{Value = cr.UpperSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
        chart.TrendLines.Add(new TrendLine{Value = cr.LowerSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
        chart.TrendLines[0].SetValue(Canvas.ZIndexProperty, 40);
        chart.TrendLines[1].SetValue(Canvas.ZIndexProperty, 40);
        chart.TrendLines[2].SetValue(Canvas.ZIndexProperty, 40);
        chart.TrendLines[3].SetValue(Canvas.ZIndexProperty, 40);
        chart.TrendLines[4].SetValue(Canvas.ZIndexProperty, 40);



        chart.DataPointWidth = cr.DataPointWidth;
        chart.Visibility = Visibility.Visible;
        Axis x = new Axis();
        x.AxisMaximum = cr.VisUpperBound;
        x.AxisMinimum = cr.VisLowerBound;
        x.AxisType = AxisTypes.Primary;

        CustomAxisLabels cal = new CustomAxisLabels();
        cal.Labels.Add(new CustomAxisLabel {From = cr.Mean, To = cr.Mean, Text = "Mean"});
        cal.Labels.Add(new CustomAxisLabel {From = cr.ChartTrippleNegativeStdDeviation,To = cr.ChartTrippleNegativeStdDeviation,Text = "LCL"});
        cal.Labels.Add(new CustomAxisLabel{From = cr.ChartTripplePositiveStdDeviation,To = cr.ChartTripplePositiveStdDeviation,Text= "UCL"});
        cal.Labels.Add(new CustomAxisLabel {From = cr.UpperSpecificationLimit, To = cr.UpperSpecificationLimit , Text = "USL"});
        cal.Labels.Add(new CustomAxisLabel {From = cr.LowerSpecificationLimit, To = cr.LowerSpecificationLimit, Text = "LSL"});

        cal.FontSize = 10;
        cal.Angle = 0;
        cal.FontColor = new SolidColorBrush(Colors.Black);
        cal.Enabled = true;


        x.CustomAxisLabels.Add(cal);
        chart.AxesX.Add(x);

        var ds = new DataSeries();
        var dpc = new DataPointCollection(cr.HistogramValues);
        ds.DataPoints = dpc;

        chart.Series.Add(ds);


        ds.ZIndex = 1;
        ds.Bevel = false;
        ds.ShadowEnabled = false;
        ds.LightingEnabled = false;
        ds.Color = new SolidColorBrush(Colors.SteelBlue);


        chart.BeginInit();
        chart.EndInit();
        chart.Measure(new Size(300, 200));
        chart.Arrange(new Rect(0, 0, 300, 200));
        chart.UpdateLayout();

        ExportToPng(new Uri("C:\\" + i + ".png"), chart);
    }

все работает отлично, кроме пользовательских ярлыков оси отсутствуют. Вот как выглядит результат:

Выход диаграммы

Как видите, для меток CustomAxis есть даже место, но они не отображаются. У кого-нибудь есть идея?

Подсказка: AnimationEnabled должен быть установлен в ложь, иначе серия еще не визуализируется, когда снимок сделан - мне потребовалось много времени, чтобы понять это.

1 ответ

Решение

Я уже нашел решение:

При превышении границ значения устанавливаются в Double.NaN. Я обнаружил, что создание всех ярлыков завершается неудачей, если какое-либо значение в коллекциях Double.Nan или Double.Infinity - похоже, ошибка в visifire.

Я решил это, добавив каждый ярлык в отдельную коллекцию.

Другие вопросы по тегам