Package ChartDirector

Examples of ChartDirector.XYChart


    /// Draw the chart and display it in the given viewer.
    /// </summary>
    private void drawChart(ChartViewer viewer) {
        // Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4)
        // background, black (000000) border, 1 pixel raised effect, and with a rounded frame.
        XYChart c = new XYChart(600, 270, 0xf4f4f4, 0x000000, 1);
        c.setRoundedFrame();

        // Re-cycle the resources of the existing chart, if any. This can improve performance
        // by reducing the frequency of garbage collections.
        c.recycle(chartViewer1.getChart());

        // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff)
        // background. Enable both horizontal and vertical grids by setting their colors to
        // grey (cccccc). Set clipping mode to clip the data lines to the plot area.
        c.setPlotArea(55, 62, 520, 175, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
        c.setClipping();

        // Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light
        // grey (dddddd) background, black (000000) border, and a glass like raised effect.
        c.addTitle("Realtime Chart Demonstration", "Times New Roman Bold Italic", 15).setBackground(0xdddddd, 0x000000, Chart.glassEffect());

        // Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the
        // legend box to the same width as the plot area and use grid layout (as opposed to
        // flow or top/down layout). This distributes the 3 legend icons evenly on top of the
        // plot area.
        LegendBox b = c.addLegend2(55, 33, 3, "Arial Bold", 9);
        b.setBackground(Chart.Transparent, Chart.Transparent);
        b.setWidth(520);

        // Configure the y-axis with a 10pts Arial Bold axis title
        c.yAxis().setTitle("Price (USD)", "Arial Bold", 10);

        // Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15
        // pixels between minor ticks. This shows more minor grid lines on the chart.
        c.xAxis().setTickDensity(75, 15);

        // Set the axes width to 2 pixels
        c.xAxis().setWidth(2);
        c.yAxis().setWidth(2);

        // Now we add the data to the chart
        Date lastTime = timeStamps[timeStamps.length - 1];
        if (lastTime != null) {
            // Set up the x-axis to show the time range in the data buffer
            c.xAxis().setDateScale(
                    new Date(lastTime.getTime() - dataInterval * timeStamps.length), lastTime);

            // Set the x-axis label format
            c.xAxis().setLabelFormat("{value|hh:nn:ss}");

            // Create a line layer to plot the lines
            LineLayer layer = c.addLineLayer2();

            // The x-coordinates are the timeStamps.
            layer.setXData(timeStamps);

            // The 3 data series are used to draw 3 lines. Here we put the latest data
            // values as part of the data set name, so you can see them updated in the
            // legend box.
            layer.addDataSet(dataSeriesA, 0xff0000, "Software: <*bgColor=FFCCCC*>"
                    + c.formatValue(dataSeriesA[dataSeriesA.length - 1], " {value|2} "));
            layer.addDataSet(dataSeriesB, 0x00cc00, "Hardware: <*bgColor=CCFFCC*>"
                    + c.formatValue(dataSeriesB[dataSeriesB.length - 1], " {value|2} "));
            layer.addDataSet(dataSeriesC, 0x0000ff, "Services: <*bgColor=CCCCFF*>"
                    + c.formatValue(dataSeriesC[dataSeriesC.length - 1], " {value|2} "));

            //
            // To show the capabilities of ChartDirector, we are add a movable threshold
            // line to the chart and dynamically print a warning message on the chart if
            // a data value exceeds the threshold
            //

            // Add a red mark line to the chart, with the mark label shown at the left of
            // the mark line.
            double thresholdValue = Double.parseDouble(alarmThreshold.getText());
            Mark m = c.yAxis().addMark(thresholdValue, 0xff0000, "Alarm = " + thresholdValue);
            m.setAlignment(Chart.Left);
            m.setBackground(0xffcccc);

            if ((dataSeriesC[dataSeriesC.length - 1] > thresholdValue)
                    || (dataSeriesB[dataSeriesB.length - 1] > thresholdValue)) {
                // Add an alarm message as a custom text box on top-right corner of the
                // plot area if the latest data value exceeds threshold.
                c.addText(575, 62, "Alarm - Latest Value Exceeded Threshold",
                        "Arial Bold Italic", 10, 0xffffff, Chart.TopRight).setBackground(0xdd0000);
            }

            // Fill the region above the threshold as semi-transparent red (80ff8888)
            c.addInterLineLayer(layer.getLine(1), m.getLine(), 0x80ff8888, Chart.Transparent);
            c.addInterLineLayer(layer.getLine(2), m.getLine(), 0x80ff8888, Chart.Transparent);
        }

        // Set the chart image to the ChartViewer
        chartViewer1.setChart(c);
    }
View Full Code Here


    /// Draw the chart and display it in the given viewer.
    /// </summary>
    private void drawChart(ChartViewer viewer) {
        // Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4)
        // background, black (000000) border, 1 pixel raised effect, and with a rounded frame.
        XYChart c = new XYChart(600, 270, 0xf4f4f4, 0x000000, 1);
        c.setRoundedFrame();

        // Re-cycle the resources of the existing chart, if any. This can improve performance
        // by reducing the frequency of garbage collections.
        c.recycle(chartViewer1.getChart());

        // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff)
        // background. Enable both horizontal and vertical grids by setting their colors to
        // grey (cccccc). Set clipping mode to clip the data lines to the plot area.
        c.setPlotArea(55, 62, 520, 175, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
        c.setClipping();

        // Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light
        // grey (dddddd) background, black (000000) border, and a glass like raised effect.
        c.addTitle("Realtime Chart Demonstration", "Times New Roman Bold Italic", 15).setBackground(0xdddddd, 0x000000, Chart.glassEffect());

        // Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the
        // legend box to the same width as the plot area and use grid layout (as opposed to
        // flow or top/down layout). This distributes the 3 legend icons evenly on top of the
        // plot area.
        LegendBox b = c.addLegend2(55, 33, 3, "Arial Bold", 9);
        b.setBackground(Chart.Transparent, Chart.Transparent);
        b.setWidth(520);

        // Configure the y-axis with a 10pts Arial Bold axis title
        c.yAxis().setTitle("Price (USD)", "Arial Bold", 10);

        // Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15
        // pixels between minor ticks. This shows more minor grid lines on the chart.
        c.xAxis().setTickDensity(75, 15);

        // Set the axes width to 2 pixels
        c.xAxis().setWidth(2);
        c.yAxis().setWidth(2);

        // Now we add the data to the chart
        Date lastTime = timeStamps[timeStamps.length - 1];
        if (lastTime != null) {
            // Set up the x-axis to show the time range in the data buffer
            c.xAxis().setDateScale(
                    new Date(lastTime.getTime() - dataInterval * timeStamps.length), lastTime);

            // Set the x-axis label format
            c.xAxis().setLabelFormat("{value|hh:nn:ss}");

            // Create a line layer to plot the lines
            LineLayer layer = c.addLineLayer2();

            // The x-coordinates are the timeStamps.
            layer.setXData(timeStamps);

            // The 3 data series are used to draw 3 lines. Here we put the latest data
            // values as part of the data set name, so you can see them updated in the
            // legend box.
            layer.addDataSet(dataSeriesA, 0xff0000, "Software: <*bgColor=FFCCCC*>"
                    + c.formatValue(dataSeriesA[dataSeriesA.length - 1], " {value|2} "));
            layer.addDataSet(dataSeriesB, 0x00cc00, "Hardware: <*bgColor=CCFFCC*>"
                    + c.formatValue(dataSeriesB[dataSeriesB.length - 1], " {value|2} "));
            layer.addDataSet(dataSeriesC, 0x0000ff, "Services: <*bgColor=CCCCFF*>"
                    + c.formatValue(dataSeriesC[dataSeriesC.length - 1], " {value|2} "));

            //
            // To show the capabilities of ChartDirector, we are add a movable threshold
            // line to the chart and dynamically print a warning message on the chart if
            // a data value exceeds the threshold
            //

            // Add a red mark line to the chart, with the mark label shown at the left of
            // the mark line.
            double thresholdValue = Double.parseDouble(alarmThreshold.getText());
            Mark m = c.yAxis().addMark(thresholdValue, 0xff0000, "Alarm = " + thresholdValue);
            m.setAlignment(Chart.Left);
            m.setBackground(0xffcccc);

            if ((dataSeriesC[dataSeriesC.length - 1] > thresholdValue)
                    || (dataSeriesB[dataSeriesB.length - 1] > thresholdValue)) {
                // Add an alarm message as a custom text box on top-right corner of the
                // plot area if the latest data value exceeds threshold.
                c.addText(575, 62, "Alarm - Latest Value Exceeded Threshold",
                        "Arial Bold Italic", 10, 0xffffff, Chart.TopRight).setBackground(0xdd0000);
            }

            // Fill the region above the threshold as semi-transparent red (80ff8888)
            c.addInterLineLayer(layer.getLine(1), m.getLine(), 0x80ff8888, Chart.Transparent);
            c.addInterLineLayer(layer.getLine(2), m.getLine(), 0x80ff8888, Chart.Transparent);
        }

        // Set the chart image to the ChartViewer
        chartViewer1.setChart(c);
    }
View Full Code Here

    /// Draw the chart and display it in the given viewer.
    /// </summary>
    private void drawChart(ChartViewer viewer) {
        // Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4)
        // background, black (000000) border, 1 pixel raised effect, and with a rounded frame.
        XYChart c = new XYChart(600, 270, 0xf4f4f4, 0x000000, 1);
        c.setRoundedFrame();

        // Re-cycle the resources of the existing chart, if any. This can improve performance
        // by reducing the frequency of garbage collections.
        c.recycle(chartViewer1.getChart());

        // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff)
        // background. Enable both horizontal and vertical grids by setting their colors to
        // grey (cccccc). Set clipping mode to clip the data lines to the plot area.
        c.setPlotArea(55, 62, 520, 175, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
        c.setClipping();

        // Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light
        // grey (dddddd) background, black (000000) border, and a glass like raised effect.
        c.addTitle("Realtime Chart Demonstration", "Times New Roman Bold Italic", 15).setBackground(0xdddddd, 0x000000, Chart.glassEffect());

        // Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the
        // legend box to the same width as the plot area and use grid layout (as opposed to
        // flow or top/down layout). This distributes the 3 legend icons evenly on top of the
        // plot area.
        LegendBox b = c.addLegend2(55, 33, 3, "Arial Bold", 9);
        b.setBackground(Chart.Transparent, Chart.Transparent);
        b.setWidth(520);

        // Configure the y-axis with a 10pts Arial Bold axis title
        c.yAxis().setTitle("Price (USD)", "Arial Bold", 10);

        // Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15
        // pixels between minor ticks. This shows more minor grid lines on the chart.
        c.xAxis().setTickDensity(75, 15);

        // Set the axes width to 2 pixels
        c.xAxis().setWidth(2);
        c.yAxis().setWidth(2);

        // Now we add the data to the chart
        Date lastTime = timeStamps[timeStamps.length - 1];
        if (lastTime != null) {
            // Set up the x-axis to show the time range in the data buffer
            c.xAxis().setDateScale(
                    new Date(lastTime.getTime() - dataInterval * timeStamps.length), lastTime);

            // Set the x-axis label format
            c.xAxis().setLabelFormat("{value|hh:nn:ss}");

            // Create a line layer to plot the lines
            LineLayer layer = c.addLineLayer2();

            // The x-coordinates are the timeStamps.
            layer.setXData(timeStamps);

            // The 3 data series are used to draw 3 lines. Here we put the latest data
            // values as part of the data set name, so you can see them updated in the
            // legend box.
            layer.addDataSet(dataSeriesA, 0xff0000, "Software: <*bgColor=FFCCCC*>"
                    + c.formatValue(dataSeriesA[dataSeriesA.length - 1], " {value|2} "));
            layer.addDataSet(dataSeriesB, 0x00cc00, "Hardware: <*bgColor=CCFFCC*>"
                    + c.formatValue(dataSeriesB[dataSeriesB.length - 1], " {value|2} "));
            layer.addDataSet(dataSeriesC, 0x0000ff, "Services: <*bgColor=CCCCFF*>"
                    + c.formatValue(dataSeriesC[dataSeriesC.length - 1], " {value|2} "));

            //
            // To show the capabilities of ChartDirector, we are add a movable threshold
            // line to the chart and dynamically print a warning message on the chart if
            // a data value exceeds the threshold
            //

            // Add a red mark line to the chart, with the mark label shown at the left of
            // the mark line.
            double thresholdValue = Double.parseDouble(alarmThreshold.getText());
            Mark m = c.yAxis().addMark(thresholdValue, 0xff0000, "Alarm = " + thresholdValue);
            m.setAlignment(Chart.Left);
            m.setBackground(0xffcccc);

            if ((dataSeriesC[dataSeriesC.length - 1] > thresholdValue)
                    || (dataSeriesB[dataSeriesB.length - 1] > thresholdValue)) {
                // Add an alarm message as a custom text box on top-right corner of the
                // plot area if the latest data value exceeds threshold.
                c.addText(575, 62, "Alarm - Latest Value Exceeded Threshold",
                        "Arial Bold Italic", 10, 0xffffff, Chart.TopRight).setBackground(0xdd0000);
            }

            // Fill the region above the threshold as semi-transparent red (80ff8888)
            c.addInterLineLayer(layer.getLine(1), m.getLine(), 0x80ff8888, Chart.Transparent);
            c.addInterLineLayer(layer.getLine(2), m.getLine(), 0x80ff8888, Chart.Transparent);
        }

        // Set the chart image to the ChartViewer
        chartViewer1.setChart(c);
    }
View Full Code Here

TOP

Related Classes of ChartDirector.XYChart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.