Show several highcharts in a web form of aspx

2

I have been testing the highcharts on asp.net and they have worked well for me by defining them in the following way

In the .aspx:

<asp:Literal id="chrtMyChart" runat="server"></asp:Literal>

and in the .aspx.cs:

public void Grafica_Chart(int paciente, String Hora)
        {

            byte[] Datos = null;
            byte[] Datos2 = null;
            byte[] Datos3 = null;
            List<int> graficoY = new List<int>();
            Datos = selectAlarmas(paciente,Hora);
            Datos2 = selectAlarmas2(paciente,Hora);
            Datos3 = selectAlarmas3(paciente,Hora);
            if (Datos == null)
            {
                Datos = new byte[1];
            }
            if (Datos2 == null)
            {
                Datos2 = new byte[1];
            }
            if (Datos3 == null)
            {
                Datos3 = new byte[1];
            }

            Object[] chartValues = new Object[Datos.Length];
            Object[] chartValues2 = new Object[Datos2.Length];
            Object[] chartValues3 = new Object[Datos3.Length];
            for (int i = 0; i < Datos.Length; i++)
            {
                chartValues[i] = Datos[i];
            }
            for (int i = 0; i < Datos2.Length; i++)
            {
                chartValues2[i] = Datos2[i];
            }
            for (int i = 0; i < Datos3.Length; i++)
            {
                chartValues3[i] = Datos3[i];
            }
            // Declare the HighCharts object    
            DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("StockChart")
                        .InitChart(new Chart
                        {
                            Type = ChartTypes.Line,
                            ZoomType = ZoomTypes.X,
                            Width = 900,
                            Height = 300,
                            BackgroundColor = new BackColorOrGradient(System.Drawing.Color.Black),
                        })
                        .SetTitle(new Title
                        {
                            Text = ""
                        })
                        .SetPlotOptions(new PlotOptions
                        {
                            Line = new PlotOptionsLine
                            {
                                EnableMouseTracking = false,
                                Animation = new Animation(true) { },
                                Visible = false
                            },
                        })
                        .SetXAxis(new XAxis
                        {
                            Labels = new XAxisLabels
                            {
                                Enabled = false
                            }
                        })
                        .SetYAxis(new YAxis
                        {
                            Title = new YAxisTitle
                            {
                                Text = ""
                            },
                            Labels = new YAxisLabels
                            {
                                Enabled = false
                            }

                        })
                        .SetSeries(new[]
                        {
                        new Series
                        {
                            Name = "ECG1",
                            Data = new Data(chartValues),   // Here we put the dbase data into the chart  
                            Color = System.Drawing.Color.Lime
                        },
                        new Series
                        {
                            Name = "ECG2",
                            Data = new Data(chartValues2),
                            Color = System.Drawing.Color.DarkTurquoise

                        },
                        new Series
                        {
                            Name = "ECG3",
                            Data = new Data(chartValues3),
                            Color = System.Drawing.Color.Red
                        }
                    });

            chrtMyChart.Text = chart.ToHtmlString(); // Let's visualize the chart into the webform.

        }

and it works fine, but I want to see several graphics in the same ASP and they are not visualized by copying the code fragment and changing the identifier I would like to know how to do to be able to visualize about 10 graphics on the same page Thanks: D

    
asked by Sebastian Mateus Villegas 08.11.2016 в 16:10
source

1 answer

0

When declaring the HightChart object, you should be assigned a unique id if there are going to be several graphs in the same webform.

 // Declare the HighCharts object    
 DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("StockChart")

I think you were referring to changing the identifier of:

<asp:Literal id="chrtMyChart" runat="server"></asp:Literal>

You may have repeated the id StockChart for all graphs.

    
answered by 16.12.2016 в 10:09