彩票走势图

图表控件ChartDirector使用教程:坐标设置详解(代码示例)

原创|其它|编辑:郝浩|2012-10-18 09:38:57.000|阅读 2380 次

概述:最近在尝试在ChartDirector里进行坐标的设置,想在这里写写最近最近的学习成果。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

最近在尝试在ChartDirector里进行坐标的设置,想在这里写写最近最近的学习成果。

下面是我的代码实例,里面就是实现如何在ChartDirector里进行坐标的设置,代码如下:

  public void createChart(ChartViewer viewer, int index)
    {
   
     // 这是两组数据,X和Y会一一对应生成;多在多纵轴图中使用,横坐标点会自动调整。
        double[] dataY0 = { 4.5, 5};
        Date[] dataX0 = {
          new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(2000,
            8, 6).getTime()
           };

        double[] dataY1 = {7, 6.5, 6, 5, 6.5, 7, 6, 5.5, 5,9,8,7,8};
        Date[] dataX1 = {new GregorianCalendar(1999, 1, 1).getTime(),
            new GregorianCalendar(1999, 6, 1).getTime(), new GregorianCalendar(1999,
            11, 1).getTime(), new GregorianCalendar(1999, 11, 15).getTime(),
            new GregorianCalendar(1999, 12, 9).getTime(), new GregorianCalendar(2000,
            2, 3).getTime(), new GregorianCalendar(2000, 7, 13).getTime(),
            new GregorianCalendar(2001, 4, 5).getTime(), new GregorianCalendar(2001,
            8, 16).getTime(), new GregorianCalendar(2001,
                    10, 16).getTime(),new GregorianCalendar(2001,
                            12, 16).getTime(),new GregorianCalendar(2002,
                                    2, 16).getTime(),new GregorianCalendar(2002,
                                            4, 16).getTime()};
      //这是单独的横坐标数据,横坐标会根据数据进行调整,Y轴会按照顺利一一对应。
        Date[] dataX2 = {
                new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(1999, 4, 1).getTime(),
                new GregorianCalendar(1999, 8, 9).getTime(), new GregorianCalendar(2000,1, 1).getTime(),
                new GregorianCalendar(2000, 4, 1).getTime(),new GregorianCalendar(2001, 8, 1).getTime(),
               };

        //创建图形的大小为 500 x 270 pixels, with a pale blue
        // (e0e0ff) background, black border, 1 pixel 3D border effect and rounded
        XYChart c = new XYChart(700, 500, 0xe0e0ff, 0x000000, 1);
        c.setRoundedFrame();

        // 起点坐标是 (55, 60) ,图形大小是520 x 200 pixels, with white
        c.setPlotArea(55, 60, 500, 300, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);

        // Add a legend box at (55, 32) (top of the chart) with horizontal layout.
        // Use 9 pts Arial Bold font. Set the background and border color to
        // Transparent.
        c.addLegend(55, 32, false, "Arial Bold", 9).setBackground(Chart.Transparent);

        // Add a title box to the chart using 15 pts Times Bold Italic font. The text
        // is white (ffffff) on a deep blue (000088) background, with soft lighting
        // effect from the right side.
        c.addTitle("Long Term Interest Rates", "Times New Roman Bold Italic", 15,
            0xffffff).setBackground(0x000088, -1, Chart.softLighting(Chart.Right));

        // 左边的Y轴
        c.yAxis().setTitle("value").setAlignment(Chart.TopLeft2);
       
        // 右边的Y轴
        c.yAxis2().setTitle("Load\n(Mbps)").setAlignment(Chart.TopRight2);
        c.yAxis2().setColors(0x008000, 0x008000, 0x008000);

        //左边距图形50的Y轴
        Axis leftAxis = c.addAxis(Chart.Left, 50);
        leftAxis.setTitle("Temp\n(C)").setAlignment(Chart.TopLeft2);
        leftAxis.setColors(0x0000cc, 0x0000cc, 0x0000cc);
       
        // 右边距图形50的Y轴
        Axis rightAxis = c.addAxis(Chart.Right, 50);
        rightAxis.setTitle("Error\n(%)").setAlignment(Chart.TopRight2);
        rightAxis.setColors(0xcccccc, 0xffffff, 0xffffff);


        //加载两组数据(XY是一一对应的,同时添加的)
        LineLayer  layer0 = c.addLineLayer(dataY0, 0xff0000, "Country AAA");
        layer0.setXData(dataX0);
        layer0.setLineWidth(1);

        LineLayer layer1 = c.addLineLayer(dataY1, 0x0000ff, "Country BBB");
        layer1.setXData(dataX1);
        layer1.setLineWidth(2);
        layer1.setUseYAxis(leftAxis);
       
        // 横坐标步长
        c.xAxis().setLabelStep(2);
//        // 统一给横坐标设值
//        c.xAxis().setLabels(dataX2);
       
        // 横坐标的标题
        c.xAxis().setTitle("Hour of Day");
    
        // output the chart
        viewer.setImage(c.makeImage());

        //{x|mmm dd, yyyy}横坐标的时间格式化
        viewer.setImageMap(c.getHTMLImageMap("clickable", "",
            "title='{dataSetName} change to {value}% on {x|mmm dd, yyyy}'"));

    }
  public static void main(String[] args)
    {
        //Instantiate an instance of this demo module
        DemoModule demo = new multiaxes();

        //Create and set up the main window
        JFrame frame = new JFrame(demo.toString());
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);} });
        frame.getContentPane().setBackground(Color.white);

        // Create the chart and put them in the content pane
        ChartViewer viewer = new ChartViewer();
        demo.createChart(viewer, 0);
        frame.getContentPane().add(viewer);

        // Display the window
        frame.pack();
        frame.setVisible(true);
    
        
    }

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:新浪博客

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP