Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2015
    Messaggi
    43

    [C#] Chart senza intervalli vuoti

    Ciao a tutti,

    ho un problema che non riesco a risolvere che vorrei sottoporvi.

    Ho bisogno di mostrare il classico grafico dato\tempo (con asse X composto da DateTime e asse Y composto da float) senza punti nulli.
    Ad esempio:

    Punto 1: 10/10/12
    Punto 2: 11/10/12
    Punto 3: 13/10/12

    codice:
    this.ChartType = SeriesChartType.Line;
    this.XValueType = ChartValueType.DateTime;
    this.Points.AddXY(*DateTime 10/10/12*, *double*);
    this.Points.AddXY(*DateTime 11/10/12*, *double*);
    this.Points.AddXY(*DateTime 13/10/12*, *double*);
    Il problema è che graficamente viene mostrato un punto 12/10/12 come media tra il punto 2 e il punto 3 (in totale quindi 4 punti). Io invece vorrei escludere i punti nulli. Ho fatto tantissime ricerche senza trovare alcuna soluzione adeguata. Attualmente ho risolto definendo valori String sull'asse X ma questo comporta diverse complicazioni sulle manipolazioni successive.
    Grazie anticipatamente
    Ultima modifica di LsKoder; 03-05-2015 a 11:18

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Ma cosa hai usato per la visualizzazione? Quale codice?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2015
    Messaggi
    43
    Riporto parte di codice relativo alla definizione del chart, spero ti riferisca a questo:

    codice:
    System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
    this.chart0 = new System.Windows.Forms.DataVisualization.Charting.Chart();
    ((System.ComponentModel.ISupportInitialize)(this.chart0)).BeginInit();
    this.chart0.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
    this.chart0.BackColor = System.Drawing.Color.Transparent;
    chartArea1.Name = "ChartArea1";
    this.chart0.ChartAreas.Add(chartArea1);
    legend1.Name = "Legend1";
    this.chart0.Legends.Add(legend1);
    this.chart0.Location = new System.Drawing.Point(0, 1);
    this.chart0.Name = "chart0";
    series1.ChartArea = "ChartArea1";
    series1.Legend = "Legend1";
    series1.Name = "Series1";
    this.chart0.Series.Add(series1);
    this.chart0.Size = new System.Drawing.Size(1143, 212);
    this.chart0.TabIndex = 0;
    this.chart0.Text = "chart0";
    this.chart0.MouseClick += new System.Windows.Forms.MouseEventHandler(this.chart_Click);
    this.chart0.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    this.Controls.Add(this.chart0);
    ((System.ComponentModel.ISupportInitialize)(this.chart0)).EndInit();
    Successivamente, in fase di esecuzione l'utente selezionerà alcune informazioni e tramite la funzione addPoint() inserirò dati nella series[0] del chart su una Form separata ed effettuerò la seguente configurazione:
    codice:
    chart0.ChartAreas[0].Axes[0].Title = "label_x";
    chart0.ChartAreas[0].Axes[1].Title = "label_y";
    chart0.ChartAreas[0].Axes[1].LabelStyle.TruncatedLabels = true;
    chart0.ChartAreas[0].AxisY.MaximumAutoSize = 12; 
    chart0.ChartAreas[0].AxisY.Interval = ((chart0.ChartAreas[0].AxisY.Maximum - chart0.ChartAreas[0].AxisY.Minimum) / 8);
    chart0.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
    chart0.ChartAreas[0].CursorX.LineColor = Color.Blue;
    chart0.ChartAreas[0].Position.Y = 0;
    chart0.ChartAreas[0].Position.Height = 100;
    chart0.ChartAreas[0].Position.X = 0;
    chart0.ChartAreas[0].Position.Width = 87;
    chart0.Legends[0].BackColor = Color.Transparent;
    chart0.ChartAreas[0].Axes[1].LabelStyle.Format = "0.000";
    ...

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2015
    Messaggi
    43
    Ho risolto modificando la proprietà della serie IsxValueIndexed a true.

    https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.