Class ChartData


  • public class ChartData
    extends Container
    The ChartData class represents a table with data that would be displayed in the chart. Here's a sample:
          double[] xAxis = new double[0];
          double[] pressureyAxis = new double[0]; 
          Series pressureSeries = new Series("Pression", xAxis, pressureyAxis, Color.BLUE);
          int cols = 24, rows = 5;
          XYChart chart = new XYChart();
          chart.showHGrids = chart.showVGrids = true; // Shows grids.
          chart.showTitle = true; // Shows title.
          chart.showYValues = true; // Shows the Y axis values.
          chart.yDecimalPlaces = 0; // No decimal places.
          chart.setXAxis(0, 240, 24); // The X axis is time in minutes. It has an interval of 5 minutes and a maximum of 2 hours.
          chart.setYAxis(0, 240, 24); // The Y axis is different for each graph.
    
          chart.snapToTop = chart.snapToBottom = true;
          String[][] data = new String[rows][cols];
          String[] tit = new String[rows];
          for (int r = 0; r < rows; r++)
          {
             tit[r] = "row "+(r+1);
             for (int c = 0; c < cols; c++)
                data[r][c] = "999";
          }
    
          ChartData cd1 = new ChartData(chart, tit, data);
          cd1.lineColor = Color.BLACK;
          cd1.setFont(font.adjustedBy(-2));
          cd1.snapToTop = true;
    
          ChartData cd2 = new ChartData(chart, data);
          cd2.lineColor = Color.BLACK;
          cd2.setFont(font.adjustedBy(-2));
          cd2.snapToBottom = true;
    
          add(cd1,LEFT,TOP+25,FILL,PREFERRED);
          add(cd2,LEFT,BOTTOM-25,FILL,PREFERRED);
          add(chart,LEFT,AFTER,FILL,FIT,cd1);
          cd2.bringToFront();
          cd1.bringToFront();
          chart.showLines = false;
          chart.yValuesSize = fm.stringWidth("99999");
          chart.series.addElement(pressureSeries);
          // setup the xy chart
          pressureSeries.xValues = new double[]{10,20,30,40,50};
          pressureSeries.yValues = new double[]{10,20,30,40,35};
          try
          {
             pressureSeries.dot = Resources.radioBkg.getNormalInstance(fmH,fmH,-1);
          }
          catch (ImageException e)
          {
             MessageBox.showException(e, true);
          }
          cd2.reposition();
        
    Since:
    TotalCross 2.0
    • Field Detail

      • chart

        protected Chart chart
      • lineColor

        public int lineColor
      • fillColor2

        public int fillColor2
      • titleForeColor

        public int titleForeColor
      • titleBackColor

        public int titleBackColor
      • selectedCol

        public int selectedCol
      • selectedRow

        public int selectedRow
      • snapToTop

        public boolean snapToTop
      • snapToBottom

        public boolean snapToBottom
      • use2ndColorEveryXColumns

        public int use2ndColorEveryXColumns
      • preferredCellHeight

        public int preferredCellHeight
        The height of the cell when using PREFERRED, defined as a % of the control's font height. Default value is 100(%).
    • Constructor Detail

      • ChartData

        public ChartData​(Chart chart)
        Constructs an empty ChartData.
      • ChartData

        public ChartData​(Chart chart,
                         ChartData.ChartDataRow[] data)
        Constructs a ChartData with the given data.
        Parameters:
        data - The values to be displayed in the format [rows][cols]
    • Method Detail

      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Container
        Draws the border (if any). If you override this method, be sure to call super.onPaint(g);, or the border will not be drawn.
        Overrides:
        onPaint in class Container
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • onEvent

        public void onEvent​(Event e)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        e - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • reposition

        public void reposition()
        Description copied from class: Control
        Reposition this control, calling again setRect with the original parameters.
        Overrides:
        reposition in class Control
      • getPreferredHeight

        public int getPreferredHeight()
        Description copied from class: Control
        Returns the preferred height of this control.
        Overrides:
        getPreferredHeight in class Control
      • addLine

        public void addLine​(int pos,
                            ChartData.ChartDataRow row)
        Adds a new row. Pass -1 to add at the end
      • removeLine

        public void removeLine​(int pos)
      • removeLine

        public void removeLine​(java.lang.String title)