轴标签值删除

时间:2018-03-29 00:21:52

标签: c# winforms mschart

我遇到了一个问题(如下面的屏幕截图所示),我在Visual C#中的图表看起来很棒,但我想删除X轴上的第一个和最后一个轴间隔标签(特别是&# 34; 3750"和" 98250"在我的条形图中)。

换句话说,这两个标签不应该是可见的/什么也不显示。

代码:

private void btnRun_Click(object sender, EventArgs e)
    {
        double numIter, PvMean, PvStDev = 0;
        int nMin, nMax, numBins = 0;

        //NOTE: n is # vehicles sold; numBins is # of bins
        numIter = double.Parse(txtNumIter.Text);
        numBins = int.Parse(txtNumBins.Text);
        PvMean = double.Parse(txtMean.Text);
        PvStDev = double.Parse(txtStDev.Text);
        nMin = int.Parse(txtMin.Text);
        nMax = int.Parse(txtMax.Text);


        //+- 3 st devs
        PvMin = ((-3) * PvStDev) + PvMean;
        PvMax = (3 * PvStDev) + PvMean;

        PtMin = nMin * PvMin;
        PtMax = nMax * PvMax;

        //Bin array
        int [] Bins = new int[numBins+1];

        Random nPv = new Random();

        double Pt, totalprofit = 0;
        int Pv, n = 0;

        int i = 0;

        for(i=0; i < numIter ; i++)
        {
            //Use these vars to be able to produce random numbers
            int PvMinRand = Convert.ToInt32(PvMin);
            int PvMaxRand = Convert.ToInt32(PvMax);

            n = nPv.Next(nMin, (nMax + 1));
            Pv = nPv.Next(PvMinRand, (PvMaxRand + 1));

            //Equation for random Pv and n to get Pt
            Pt = n * Pv;

            //Increments total profit;
            totalprofit += Pt;

            //Bin index from rand
            int index = 0;
            //Call GetBinIndex method
            index = GetBinIndex(PtMin, PtMax, numBins, Pt);
            //Incremenents bin count by 1
            Bins[index] += 1;

        }

        //Increment of chart
        double Increment, incrCount, binRange = 0;
        binRange = PtMax - PtMin;
        Increment = binRange / numBins;
        chtSim.ChartAreas[0].AxisX.Interval = Increment;


        //Graph bars for each bin loop
        int j = 1;
        for (j = 1; j < (numBins+1); j++)
        {
            //Increases incr label value for each iteration above Pt Min
            incrCount = Increment * j + PtMin;

            //Graph bar for each index
            chtSim.Series[0].Points.AddXY(incrCount, Bins[j]);

        }

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以为每个AxisLabel单独设置DataPoint

通过这样做,自动标签被删除。所以你可以写。:

int ix = chtSim.Series[0].Points.AddXY(incrCount, Bins[j]);
chtSim.Series[0].Points[ix].AxisLabel = incrCount;

..在你的循环中。

现在只显示您自己设置的标签。