ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Custom XYChart Add Scroll function Chart's x Axis value
Posted by Youngmin Jung on Jul-29-2013 10:26
Hi i try to make chart using XYChart included scroll function on C#.

i have a problem on x Axis Value. The Value attach to String but it sometimes look double value by scrolling range.
ex :
|
|
|
|
|
-------------------------------------
     0.0    A     B     C     D     E     F

0.0 is Problem ...


Is there solution about this problem?
Let me help.. plz..


private void drawChart(WinChartViewer viewer)
{
     XYChart c = new XYChart(640, 370);
     c.setPlotArea(55, 55, c.getWidth() - 80, c.getHeight() - 140, c.linearGradientColor(0, 55, 0,
      c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

      c.setClipping();
     int fontSize = 16;
     if (Target.Length > 20)
     {
         fontSize = 11;
     }
     if(Type.Equals("USER"))
     {
         c.addTitle("'" + Target + "' for each File access count", "Times New Roman Bold Italic", fontSize);
     }
     else if(Type.Equals("FILE"))
     {
         c.addTitle("'" + Target + "' for each User's access count", "Times New Roman Bold Italic", fontSize);
     }

      ChartDirector.TextBox textBox = c.xAxis().setLabelStyle();
      textBox.setMaxWidth(100);


       // Set legend icon style to use line style icon, sized for 8pt font
       c.getLegend().setLineStyleKey();
       c.getLegend().setFontSize(80);

       // Set the axis stem to transparent
       c.xAxis().setColors(Chart.Transparent);
       c.yAxis().setColors(Chart.Transparent);
       //c.yAxis().setTickDensity(
       c.xAxis().setLabels(labels);
       c.yAxis().setTitle("Access Count", "Arial Bold Italic", 10);
       c.yAxis().setMinTickInc(1);
      if(Type.Equals("USER"))
      {
          c.xAxis().setTitle("File Name", "Arial Bold Italic", 10);
       }
       else if(Type.Equals("FILE"))
        {
            c.xAxis().setTitle("User Name", "Arial Bold Italic", 10);
        }
       c.xAxis().setTitlePos(2, -3);
       c.xAxis().setTickDensity(1000);


       BarLayer layer = c.addBarLayer2(Chart.Stack, 8);

       // Add the three data sets to the bar layer
       layer.addDataSet(data, 0xff8080, "UpdateCount");
       //layer.addDataSet(dataSeriesB, 0x80ff80, "Server # 2");
       layer.setBarWidth(30);
       // Enable bar label for the whole bar
       layer.setAggregateLabelStyle();

        // Enable bar label for each segment of the stacked bar
        layer.setDataLabelStyle();

        // Set the x-axis as a date/time axis with the scale according to the view port x range.
            // When labels.length > 10, Scroll is Enabled.
            if (labels.Length >= 7)
            {
                viewer.syncLinearAxisWithViewPort("x", c.xAxis());
            }
            //================================================================================
            // Output the chart
            //================================================================================
            viewer.Chart = c;

            if (Type.Equals("USER"))
            {
                viewer.ImageMap = c.getHTMLImageMap("", "",
                "title='File = [ {xLabel} ]\\nCount = [ {value} ]'");
            }
            else if (Type.Equals("FILE"))
            {
                viewer.ImageMap = c.getHTMLImageMap("", "",
                    "title='User = [ {xLabel} ]\\nCount = [ {value} ]'");
            }
        }

        //
        // Initialize the WinChartViewer
        //
        private void initChartViewer(WinChartViewer viewer)
        {
            // Set the full x range to be the duration of the data
            viewer.setFullRange("x", 0, labels.Length);

            double viewportWidth;
            // Initialize the view port to show the latest 20% of the time range
            switch (labels.Length / 7)
            {
                case 0:
                    viewportWidth = 1;
                    break;
                case 1:
                    viewportWidth = 0.3;
                    break;
                case 2:
                    viewportWidth = 0.3;
                    break;
                default:
                    viewportWidth = 0.1;
                    break;
            }
            viewer.ViewPortWidth = viewportWidth;
            viewer.ViewPortLeft = 0.5;
        }


    }

  Re: Custom XYChart Add Scroll function Chart's x Axis value
Posted by Youngmin Jung on Jul-29-2013 13:37
I found it myself.

If i want to real Label When using Scroll bar,  do not use syncLinearAxisWithViewPort() & xAxis().setLabels().
It can be solvedlike this
{
            double startLabelIndex = viewer.getValueAtViewPort("x", viewer.ViewPortLeft);
            double endLabelIndex =
            viewer.getValueAtViewPort("x", .ViewPortLeft + viewer.ViewPortWidth);

            c.xAxis().setLinearScale(startLabelIndex, endLabelIndex, Chart.NoValue);

            for (int i = (int)(startLabelIndex); i <= endLabelIndex; ++i)
                c.xAxis().addLabel(i, labels[i]);
}

thans for read this Q