我有一个有50个条形图的列表框我想在Silverlight中打印多个页面中的所有条形图如何做到这一点请给我Complite解决方案和那个条形图已经... [英] I Have A Listbox That Has 50 Bar Chart In I Want To Print All Bar Chart In Multiple Page In Silverlight How To Do That Please Give Me Complite Solution And That Barchart Has Been...

查看:64
本文介绍了我有一个有50个条形图的列表框我想在Silverlight中打印多个页面中的所有条形图如何做到这一点请给我Complite解决方案和那个条形图已经...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是动态创建图表的示例代码。





this is the sample code of dynamically created chart .


private void NewCostVaraianceChart()
        {
            try
            {
              //  listBox2.Width = Application_Masters.FormLoader.set_layout_width();
                if (taskdata != null)
                {
                    tasklist = taskdata.ToList();
                }
                StackPanel stkpanel = new StackPanel();

                int chartwidth = 400;
                int taskcount = 3;

                //if (listBox2.Width < 1200)
                //{
                //    taskcount = 2;
                //    chartwidth = Convert.ToInt32(listBox2.Width / taskcount);
                //    chartwidth = chartwidth - 70;
                //}

                Style style = new Style(typeof(Control));
                ResourceDictionaryCollection palette = new ResourceDictionaryCollection();
                for (int i = 0; i < taskdata.Count; i++)
                {
                    Chart barChart = new Chart();

                    barChart.Style = Application.Current.Resources["ChartStyleSch"] as Style;
                    palette = new ResourceDictionaryCollection();

                    barChart.Palette.Clear();
                    barChart.Axes.Clear();
                    barChart.Series.Clear();

                    if (i % taskcount == 0)
                    {
                        stkpanel = new StackPanel();
                        stkpanel.Orientation = Orientation.Horizontal;
                    }

                    CustomColumnSeries obj_columsrs = new CustomColumnSeries();
                    barChart.Height = 225;
                    barChart.Width = chartwidth;
                    barChart.Margin = new Thickness(10, 5, 10, 5);

                    obj_columsrs.IndependentValuePath = "ProjectName";
                    obj_columsrs.AnimationSequence = AnimationSequence.FirstToLast;

                    List<chartdata> cust = new List<chartdata>();

                    cust.Add(new ChartData()
                    {
                        WorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedHour),
                        ScheduledHr = Convert.ToInt32(tasklist[i].Scheduledhr),
                        ProjectName = tasklist[i].Projectname,
                        ColumnColors = new SolidColorBrush(GetRandomColor()),
                        tcolor = new SolidColorBrush(Colors.Blue),
                        ChangedHr = Convert.ToInt32(tasklist[i].Balance),
                        ReWorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedMin)
                    });

                    List<chartdata> cust1 = new List<chartdata>();
                    cust1.Add(new ChartData()
                    {
                        WorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedHour),
                        ScheduledHr = Convert.ToInt32(tasklist[i].Scheduledhr),
                        ProjectName = tasklist[i].Projectname,
                        tcolor = new SolidColorBrush(Colors.Blue),
                        ColumnColors = new SolidColorBrush(GetRandomColor()),
                        ChangedHr = Convert.ToInt32(tasklist[i].Balance),
                        ReWorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedMin)
                    });
                    List<chartdata> cust2 = new List<chartdata>();
                    cust2.Add(new ChartData()
                    {
                        WorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedHour),
                        ScheduledHr = Convert.ToInt32(tasklist[i].Scheduledhr),
                        ProjectName = tasklist[i].Projectname,
                        tcolor = new SolidColorBrush(Colors.Blue),
                        ColumnColors = new SolidColorBrush(GetRandomColor()),
                        ChangedHr = Convert.ToInt32(tasklist[i].Balance),
                        ReWorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedMin)
                    });
                    List<chartdata> cust3 = new List<chartdata>();
                    cust3.Add(new ChartData()
                    {
                        WorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedHour),
                        ScheduledHr = Convert.ToInt32(tasklist[i].Scheduledhr),
                        ProjectName = tasklist[i].Projectname,
                        tcolor = new SolidColorBrush(Colors.Blue),
                        ColumnColors = new SolidColorBrush(GetRandomColor()),
                        ChangedHr = Convert.ToInt32(tasklist[i].Balance),
                        ReWorkedHr = Convert.ToInt32(tasklist[i].TaskWorkedMin)
                    });

                    var getMxvalue = 0.0;
                    //if (tasklist[i].Scheduledhr > tasklist[i].TaskWorkedHour)
                    //{
                    //    getMxvalue = Convert.ToInt32(tasklist[i].Scheduledhr);
                    //}
                    //else
                    //{
                    //    getMxvalue = Convert.ToInt32(tasklist[i].TaskWorkedHour);
                    //}

                    if (tasklist[i].Scheduledhr > tasklist[i].TaskWorkedHour && tasklist[i].Scheduledhr > tasklist[i].Balance && tasklist[i].Scheduledhr > tasklist[i].TaskWorkedMin)
                    {
                        getMxvalue = Convert.ToDouble(tasklist[i].Scheduledhr);
                    }
                    else if (tasklist[i].TaskWorkedHour > tasklist[i].Scheduledhr && tasklist[i].TaskWorkedHour > tasklist[i].Balance && tasklist[i].TaskWorkedHour > tasklist[i].TaskWorkedMin)
                    {
                        getMxvalue = Convert.ToDouble(tasklist[i].TaskWorkedHour);
                    }
                    else if (tasklist[i].Balance > tasklist[i].TaskWorkedHour && tasklist[i].Balance > tasklist[i].Scheduledhr && tasklist[i].Balance > tasklist[i].TaskWorkedMin)
                    {
                        getMxvalue = Convert.ToDouble(tasklist[i].Balance);
                    }
                    else if (tasklist[i].TaskWorkedMin > tasklist[i].TaskWorkedHour && tasklist[i].TaskWorkedMin > tasklist[i].Scheduledhr && tasklist[i].TaskWorkedMin > tasklist[i].Balance)
                    {
                        getMxvalue = Convert.ToDouble(tasklist[i].TaskWorkedMin);
                    }

                    var ValToRound = Math.Ceiling(Convert.ToDouble(getMxvalue) / 2);
                    if (ValToRound > 10)
                    {
                        ValToRound = RoundOff(((int)ValToRound));
                    }


                    LinearAxis linax = new LinearAxis();
                    linax.Orientation = AxisOrientation.Y;
                    barChart.Axes.Add(linax);
                    LinearAxis linax1 = barChart.Axes[0] as LinearAxis;

                    linax1.Minimum = 0;
                    linax1.Interval = ValToRound;
                    linax1.Maximum = Math.Ceiling(getMxvalue) + Math.Ceiling(ValToRound);


                    CategoryAxis catax1 = new CategoryAxis();
                    catax1.Orientation = AxisOrientation.Y;
                    barChart.Axes.Add(catax1);

                    CategoryAxis catax = barChart.Axes[1] as CategoryAxis;
                    catax.Title = ResourceFile.HoursLabel;
                    catax1.Location = AxisLocation.Left;

                    obj_columsrs.DependentValuePath = "ScheduledHr";
                    obj_columsrs.Title = "   " + ResourceFile.ScheduledLabel;
                    barChart.Series.Add(obj_columsrs);

                    style = new Style(typeof(Control));
                    style.Setters.Add(new Setter(MaxWidthProperty, 30));
                    style.Setters.Add(new Setter(BackgroundProperty, cust[0].ColumnColors));
                    style.Setters.Add(new Setter(BorderBrushProperty, cust[0].ColumnColors));
                    style.Setters.Add(new Setter(TemplateProperty, SetColumnSeriesContentTemplate("'-45,0,25,0'")));


                    ResourceDictionary dictionary = new ResourceDictionary();
                    dictionary.Add("DataPointStyle", style);
                    palette.Add(dictionary);
                    barChart.Palette = palette;
                    ((CustomColumnSeries)barChart.Series[0]).ItemsSource = cust;



                    obj_columsrs = new CustomColumnSeries();

                    obj_columsrs.IndependentValuePath = "ProjectName";
                    obj_columsrs.AnimationSequence = AnimationSequence.FirstToLast;
                    obj_columsrs.DependentValuePath = "WorkedHr";
                    obj_columsrs.Title = obj_columsrs.Title = "   " + ResourceFile.WorkedLabel;

                    style = new Style(typeof(Control));
                    style.Setters.Add(new Setter(MaxWidthProperty, 30));
                    style.Setters.Add(new Setter(BackgroundProperty, cust1[0].ColumnColors));
                    style.Setters.Add(new Setter(BorderBrushProperty, cust1[0].ColumnColors));
                    style.Setters.Add(new Setter(TemplateProperty, SetColumnSeriesContentTemplate("'-20,0,0,0'")));

                    dictionary = new ResourceDictionary();
                    dictionary.Add("DataPointStyle", style);
                    palette.Add(dictionary);
                    barChart.Palette = palette;
                    barChart.Series.Add(obj_columsrs);
                    ((CustomColumnSeries)barChart.Series[1]).ItemsSource = cust1;


                    obj_columsrs = new CustomColumnSeries();
                    obj_columsrs.IndependentValuePath = "ProjectName";
                    obj_columsrs.AnimationSequence = AnimationSequence.FirstToLast;
                    obj_columsrs.DependentValuePath = "ChangedHr";
                    obj_columsrs.Title = obj_columsrs.Title = "   " + ResourceFile.ChangeHour;
                    style = new Style(typeof(Control));
                    style.Setters.Add(new Setter(MaxWidthProperty, 30));
                    style.Setters.Add(new Setter(BackgroundProperty, cust2[0].ColumnColors));
                    style.Setters.Add(new Setter(BorderBrushProperty, cust2[0].ColumnColors));
                    style.Setters.Add(new Setter(TemplateProperty, SetColumnSeriesContentTemplate("'5,0,-25,0'")));

                    dictionary = new ResourceDictionary();
                    dictionary.Add("DataPointStyle", style);
                    palette.Add(dictionary);
                    barChart.Palette = palette;
                    barChart.Series.Add(obj_columsrs);
                    ((CustomColumnSeries)barChart.Series[2]).ItemsSource = cust2;


                    obj_columsrs = new CustomColumnSeries();
                    obj_columsrs.IndependentValuePath = "ProjectName";
                    obj_columsrs.AnimationSequence = AnimationSequence.FirstToLast;
                    obj_columsrs.DependentValuePath = "ReWorkedHr";
                    obj_columsrs.Title = obj_columsrs.Title = "   " + ResourceFile.ReworkHour;
                    style = new Style(typeof(Control));
                    style.Setters.Add(new Setter(MaxWidthProperty, 30));
                    style.Setters.Add(new Setter(BackgroundProperty, cust3[0].ColumnColors));
                    style.Setters.Add(new Setter(BorderBrushProperty, cust3[0].ColumnColors));
                    style.Setters.Add(new Setter(TemplateProperty, SetColumnSeriesContentTemplate("'30,0,-50,0'")));

                    dictionary = new ResourceDictionary();
                    dictionary.Add("DataPointStyle", style);
                    palette.Add(dictionary);
                    barChart.Palette = palette;
                    barChart.Series.Add(obj_columsrs);
                    ((CustomColumnSeries)barChart.Series[3]).ItemsSource = cust3;


                    stkpanel.Children.Add(barChart);

                    //stckprint.Children.Add(barChart);

                    if (i == taskdata.Count - 1)
                    {
                        stckprint.Children.Add(stkpanel);
                    }
                    else if ((i + 1) % taskcount == 0 && i != 0)
                    {
                        stckprint.Children.Add(stkpanel);
                    }

                }

            }
            catch (Exception)
            {
            }
        }













这是打印按钮的示例代码点击























this is the sample code of print button click








private void Print_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                int itemIndex = 0;
                pd.PrintPage += (s, pe) =>
                {

                   // StackPanel itemHost = new StackPanel();
                    while (itemIndex < stckprint.Children.Count)
                    {

                        //Viewbox lstboxprnt = new Viewbox();

                        //lstboxprnt.DataContext = lstbox.Items[itemIndex];
                        try
                        {
                         //   itemHost.Children.Add(stckprint.Children[itemIndex]);

                            stckprint.Measure(new Size(pe.PrintableArea.Width, double.PositiveInfinity));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());

                            //throw;
                        }
                        if (stckprint.DesiredSize.Height > pe.PrintableArea.Height && stckprint.Children.Count > 1 && stckprint.Children.Count >1)
                        {
                            stckprint.Children.Remove(stckprint);
                            pe.HasMorePages = true;
                            break;
                        }
                        if (stckprint.DesiredSize.Width > pe.PrintableArea.Width && stckprint.Children.Count > 1)
                        {
                            stckprint.Children.Remove(stckprint);
                            pe.HasMorePages = true;
                            break;
                        }
                        
                    }
                    pe.PageVisual = stckprint;
                    itemIndex += 1;

                };
                Viewbox viewbox = new Viewbox();
                ItemsControl itemhost = new ItemsControl();
               // itemhost.ItemsSource = stkprin;

                pd.Print("text");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());

                //throw;
            }
        }
    }















请尝试根据此代码示例提供完整的解决方案,以便正常工作





谢谢和尊重。

Vikash








plase try to give me complete solution based on this code sample that will work fine


thanks and regard.
Vikash

推荐答案

根据此代码给我完整的解决方案可以正常工作的样品



它不是那样的工作。

我们不做你的工作你好。

如果你想让别人写你的代码,你必须付钱 - 我建议你去VWorker.com并在那里问。



但请注意:你得到的是你付出的代价。支付花生,获得猴子
"give me complete solution based on this code sample that will work fine"

It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to VWorker.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys


这篇关于我有一个有50个条形图的列表框我想在Silverlight中打印多个页面中的所有条形图如何做到这一点请给我Complite解决方案和那个条形图已经...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆