Search code examples
c#zedgraph

How to set font and size of other yaxis in Zedgraph?


I know how to set font family and size to main xaxis and yaxis. But I have tried many ways to do with other yaxis when the yaxis index is y2 and y7. As the picture shows, DD-Prices is a yaxis with yaxisindex = y2, and PD-Price is a yaxis with yaxisindex = y7. enter image description here

Here is my code:

        if (plotValue.Keys.Contains("DD_CurrentPrice"))
        {
            y2 = graphArea.AddYAxis("DD - Price");
            curve = new LineItem("DD - Current Price", null, plotValue["DD_CurrentPrice"], Color.FromArgb(255, 198, 001), SymbolType.None) { YAxisIndex = y2 };
            curve.Label.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false);
            graphArea.CurveList.Add(curve);
        }

        if (plotValue.Keys.Contains("PD_MarkdownPrice") || plotValue.Keys.Contains("PD_CurrentPrice"))
        {
            y7 = graphArea.AddYAxis("PD - Price");
            if (plotValue.Keys.Contains("PD_MarkdownPrice"))
            {
                curve = new LineItem("PD - Markdown Price", null, plotValue["PD_MarkdownPrice"], Color.FromArgb(045, 186, 030), SymbolType.None) { YAxisIndex = y7 };
                curve.Label.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false);
                graphArea.CurveList.Add(curve);
            }
            if (plotValue.Keys.Contains("PD_CurrentPrice"))
            {
                curve = new LineItem("PD - Current Price", null, plotValue["PD_CurrentPrice"], Color.FromArgb(011, 138, 000), SymbolType.None) { YAxisIndex = y7 };
                curve.Label.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false);
                graphArea.CurveList.Add(curve);
            }

        }

There is no property to set the curve scale font family and size. Is there any other solution? Thanks.


Solution

  • Add the code below can solve this problem:

                Axis axis = graphArea.CurveList[y2].GetYAxis(graphArea);
                axis.Scale.FontSpec.Family = "Cambria";
                axis.Scale.FontSpec.Size = fontSize;
                axis.Title.FontSpec.Family = "Cambria";
                axis.Title.FontSpec.Size = fontSize;