c # - viser ikke forskellige diagrammer på enkeltformular

Indlæg af Hanne Mølgaard Plasc

Problem



hej jeg forsøger at repræsentere de to grafer (cirkeldiagram og stregdiagram) på en form ved hjælp af mschart kontroller .... dataene kommer fra databasen ....


Jeg bruger single chart (kpichart) kontrol til at repræsentere de to grafer ....


for det er jeg undertekst under kode


I denne kode har jeg defineret to forskellige områder til at definere to grafer .....


       public void KpiMembers\_MouseClick(object sender, MouseEventArgs e)
       {

        Series statusseries;
        Series liveserries = null;
        string area;
        Title title;

        try
        {
            var pos = e.Location;
            var results = KpiMembersTotalchart.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
            foreach (var result in results)
            {
                if (result.ChartElementType == ChartElementType.DataPoint)
                {
                    if (result.Series.Points[result.PointIndex].AxisLabel == "Live")
                    {
                        DataTable Livemembers = null;
                        Livemembers = KpiData.livemembersmembershipstatus();

                        DataTable membersalltotals = null;
                        membersalltotals = kpimembtotals.membershipTotals(dtpStartDate.Value, dtpenddate.Value);

                        KpiMembersTotalchart.ChartAreas.Clear();
                        KpiMembersTotalchart.Titles.Clear();
                        KpiMembersTotalchart.Series.Clear();


                        area = "newchart";
                        KpiMembersTotalchart.ChartAreas.Add(area);
                        liveserries = KpiMembersTotalchart.Series.Add(area);
                        liveserries.ChartArea = area;

                        title = KpiMembersTotalchart.Titles.Add("Memberstotalspoints");
                        title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
                        title.Alignment = ContentAlignment.TopLeft;
                        title.DockedToChartArea = area;


                        KpiMembersTotalchart.Titles.Add("").DockedToChartArea = area;

                        area = "subchart";
                        KpiMembersTotalchart.ChartAreas.Add(area);
                        statusseries = KpiMembersTotalchart.Series.Add(area);
                        statusseries.ChartArea = area;


                        title = KpiMembersTotalchart.Titles.Add("Live Status members by status");
                        title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
                        title.Alignment = ContentAlignment.TopLeft;
                        title.DockedToChartArea = area;

                        KpiMembersTotalchart.Titles.Add("").DockedToChartArea = area;



                        foreach (Title chartTitle in KpiMembersTotalchart.Titles)
                        {
                            chartTitle.IsDockedInsideChartArea = false;
                        }

                        foreach (ChartArea chartArea in KpiMembersTotalchart.ChartAreas)
                        {
                            chartArea.Area3DStyle.Enable3D = true;
                            chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;

                        }

                        if (area == "subchart")
                        {
                            foreach (Series charttypes in KpiMembersTotalchart.Series)
                            {
                                charttypes.ChartType = SeriesChartType.Pie;
                                charttypes["PielabelStyle"] = "Outside";
                                charttypes["DoughnutRadius"] = "30";
                                charttypes["PieDrawingStyle"] = "SoftEdge";
                                charttypes.BackGradientStyle = GradientStyle.DiagonalLeft;

                            }

                        }

                        if (area == "newchart")
                        {
                            foreach (Series chartareas in KpiMembersTotalchart.Series)
                            {
                                chartareas.ChartType = SeriesChartType.StackedColumn;
                                chartareas["ColumnDrawingStyle"] = "SoftEdge";
                                chartareas["LabelStyle"] = "Top";
                                chartareas.IsValueShownAsLabel = true;
                                chartareas.BackGradientStyle = GradientStyle.DiagonalLeft;
                            }
                        }


                        foreach (Legend legend in KpiMembersTotalchart.Legends)
                        {
                            legend.Enabled = false;
                        }

                        if (membersalltotals == null)
                        {
                            statusseries.Points.Clear();
                            statusseries.Points.AddXY("no status", 0);

                        }

                        if(Livemembers == null)
                        {

                            liveserries.Points.Clear();
                            liveserries.Points.AddXY("no membershipe", 0);

                        }
                        KpiMembersTotalchart.Series["newchart"].Points.DataBindXY(membersalltotals.Rows, "Status", membersalltotals.Rows, "Value");
                        KpiMembersTotalchart.Series["subchart"].Points.DataBindXY(Livemembers.Rows, "mshipname", Livemembers.Rows, "count");

                        if (area == "subchart")
                        {
                            foreach (Series charttypes in KpiMembersTotalchart.Series)
                            {
                                foreach (DataPoint point in charttypes.Points)
                                {
                                    switch (point.AxisLabel)
                                    {
                                        case "New": point.Color = Color.Cyan; break;
                                        case "Live": point.Color = Color.Green; break;
                                        case "Defaulter": point.Color = Color.Red; break;
                                        case "Cancelled": point.Color = Color.Orange; break;
                                        case "Completed": point.Color = Color.Blue; break;
                                        case "Frozen": point.Color = Color.Violet; break;
                                    }

                                    point.Label = string.Format("{0:0} - {1}", point.YValues[0], point.AxisLabel);
                                }
                            }
                        }
                        if (area == "newchart")
                        {
                            foreach (Series chartareas in KpiMembersTotalchart.Series)
                            {
                                foreach (DataPoint point in chartareas.Points)
                                {

                                    switch (point.AxisLabel)
                                    {
                                        case "Silver membership": point.Color = Color.Green; break;
                                        case "Gold Membership": point.Color = Color.Blue; break;
                                        //case "Refused": point.Color = Color.Red; break;
                                        case "Weekend Peak": point.Color = Color.Cyan; break;
                                        case "prspect": point.Color = Color.Indigo; break;

                                    }
                                    point.Label = string.Format("{0:0}", point.YValues[0]);
                                }

                            }
                        }
                    }

                }
            }
        }
        catch { }

    }


Mit problem er, jeg forsøger at vise de to forskellige diagrammer (den ene er cirkeldiagram og en anden er stablet kolonneoversigt) ....


men det viste to samme diagrammer (begge er cirkeldiagrammer) se nedenstående diagram Indtast billedbeskrivelse her


Jeg vil vise det stablede søjlediagram i stedet for cirkeldiagram i anden .... men det viste to samme diagrammer (pie)


jeg har opdelt den samlede formular i to områder .....


Hvad jeg skal gøre for at vise de to forskellige grafer på samme form ved hjælp af single chart control


vil nogen pls hjælpe på dette ....


Mange tak på forhånd for ideer .....

Bedste reference


Dette er et simpelt problem med logikken i din kode.


Din kode læser i øjeblikket:


                    area = "newchart";
                    ......
                    area = "subchart";
                    ......
                    if (area == "subchart")
                    ......
                    if (area == "newchart")


Dette vil naturligvis altid evaluere den første 'if' til 'true' og den anden 'if' til 'false'. Du skal omorganisere din kode, så den ikke bruger area sådan - du skal træde tilbage og omskrive din logik, der skaber de diagrammer, du har brug for.