AAChartModel / AAChartCore

📈📊☕️☕️☕️An elegant modern declarative data visualization chart framework for Android. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray方法无法减去最后加入的AASeriesElement

wxhwan opened this issue · comments

我初始化了5个AASeriesElement分别是A,B,C,D,E,有个需求就是我点击一个按钮就减去一个AASeriesElement,每当我要减去第5个AASeriesElement的时候,此时AAChartView无论有多少个AASeriesElement总是无法减去第5个,感觉像是一直持有第5个AASeriesElement,其他4个都是正常的,我只能通过aa_drawChartWithChartOptions方法重绘才不会出现这种情况,请问一下大佬这是啥问题呀

5个按钮对应着5个AASeriesElement,独立控制对应的AASeriesElement,我点第5个按钮一直无法减去它对应的AASeriesElement,纵使我视图上减的只剩下这第5个了

此外,开发平台是android

有个需求就是我点击一个按钮就减去一个AASeriesElement

你这里调用的是 AAChartView 的哪个方法?

点击了按钮之后我会创建一个新的数组并填充新的数据,之后我调用AAChartView 的aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray方法,没有再调用其他的方法

  public void aa_showTheSeriesElementContent(Integer elementIndex) {
        String javaScriptStr = "showTheSeriesElementContentWithIndex('"
                + elementIndex + "')";
        this.safeEvaluateJavaScriptString(javaScriptStr);
    }

    public void aa_hideTheSeriesElementContent(Integer elementIndex) {
        String javaScriptStr = "hideTheSeriesElementContentWithIndex('"
                + elementIndex + "')";
        this.safeEvaluateJavaScriptString(javaScriptStr);
    }

如果只是单纯地想要隐藏或显示某一个 AASeriesElement, 可以使用 AAChartView 中的上面两个方法, demo 中有相关的使用示例, 运行查看即可.

    public void aa_addElementToChartSeries(AASeriesElement aaSeriesElement) {
        String pureElementJsonStr = new Gson().toJson(aaSeriesElement);
        String javaScriptStr = "addElementToChartSeriesWithElement('"
                + pureElementJsonStr + "')";
        this.safeEvaluateJavaScriptString(javaScriptStr);
    }

    public void aa_removeElementFromChartSeries(Integer elementIndex) {
        String javaScriptStr = "removeElementFromChartSeriesWithElementIndex('"
                + elementIndex + "')";
        this.safeEvaluateJavaScriptString(javaScriptStr);
    }

如果想要直接添加 AASeriesElement 或移除某一个指定的 AASeriesElement , 可以使用 AAChartView 中的上面这两个方法, demo 中暂时没有添加使用示例, 不过你可以自行测试一下试试. 感觉你需要的实现的需求, 应该是直接使用这两个方法就可以了.

这两个方法, 内部调用的实际是这两个 JS 方法:

        function addElementToChartSeriesWithElement(elementStr) {
            var seriesElement = JSON.parse(elementStr);
            aaGlobalChart.addSeries(seriesElement);
        }

        function removeElementFromChartSeriesWithElementIndex(elementIndex) {
            var seriesElement = aaGlobalChart.series[elementIndex];
            if (seriesElement) {
                seriesElement.remove(true);
            }
        }

参考对应的在线文档:

好的,感谢大佬,我还有个疑问,就是在如何在折线图显示Y坐标轴?我按照“即时刷新图表数据”即时刷新图表数据分类的折线图中的代码去修改,发现虽然会显示Y坐标轴,但是折现图反映出来的数据和我设置的数据对不上,且x轴会有部分超出屏幕,感觉像是被放大了一样;另外我尝试了“通过Options绘图”分类中的customLegendStyle中的代码尝试修改,发现添加图一
图一
中的代码也会有Y坐标轴显示,但是会多出很多y轴,就像图二
图二
一样被细分成了很多小方块。我应该怎么实现在不影响原有折线图样式的基础上添加一条Y坐标轴(如图三)
图三
,并且不显示y轴的标题(因为我发现AAChartModel.yAxisVisible这个方法是同是控制Y坐标轴与Y轴标题的显示和隐藏)

我应该怎么实现在不影响原有折线图样式的基础上添加一条Y坐标轴(如图三)

参考 AAYAxis 的这个属性:

    public Object[] tickPositions; // An array defining where the ticks are laid out on the axis. 

默认情况下, 是根据你给 AASeriesElementdata 数组中的数据, 自动生成 Y 轴的网格线的, tickPositions 则是用来自定义 Y轴的网格线对应的数值的. 参考在线文档:

如文档所说, tickPositions: An array defining where the ticks are laid out on the axis. This overrides the default behaviour of tickPixelInterval and tickInterval.

并且不显示y轴的标题(因为我发现AAChartModel.yAxisVisible这个方法是同是控制Y坐标轴与Y轴标题的显示和隐藏)

直接设置 Y 轴文字内容为空字符串 "" 即可.

我应该怎么实现在不影响原有折线图样式的基础上添加一条Y坐标轴(如图三)

参考 AAYAxis 的这个属性:

    public Object[] tickPositions; // An array defining where the ticks are laid out on the axis. 

默认情况下, 是根据你给 AASeriesElementdata 数组中的数据, 自动生成 Y 轴的网格线的, tickPositions 则是用来自定义 Y轴的网格线对应的数值的. 参考在线文档:

如文档所说, tickPositions: An array defining where the ticks are laid out on the axis. This overrides the default behaviour of tickPixelInterval and tickInterval.

不不不,我并不想自定义y轴的数值,因为我的数据是数字,所以我觉得自带的挺好的,我就只是想要显示y轴线,就像x轴一样,因为只显示了x轴而不显示y轴感觉怪怪的可能会被挑毛病

我就只是想要显示y轴线,就像x轴一样,

那你应该就按照图 1 中的代码进行配置就行了.

但是会多出很多y轴,就像图二

至于你这里说的这个问题, 那是因为你配置了次网格线 minorGrid , 只要将 minorGrid 相关的代码删除即可(因为默认不会显示次网格线 minorGrid).

Y 轴网格线相关内容, 参考 iOS 版本中的相似问题:

如果你不是想设置网格线, 而是想设置 Y 轴轴线的话, 参考 AAYAxis 的属性:

    public Number lineWidth; //坐标轴轴线宽度
    public String lineColor; //坐标轴轴线线颜色

在线 API 文档:

至于你这里说的这个问题, 那是因为你配置了次网格线 minorGrid , 只要将 minorGrid 相关的代码删除即可(因为默认不会显示次网格线 minorGrid).

这个我试过了,我给xAxis和yAxis这两个属性只加了gridLineWidth和gridLineColor方法,结果就是变成了网格状的统计图了(如图一)
图一
而我只想要一个y轴(如图二)
图二

设置 xAxisgridLineWidth 网格线宽度为 0 , 不就可以隐藏 X 轴网格线, 而只剩下 Y 轴的网格线了吗?

设置 xAxisgridLineWidth 网格线宽度为 0 , 不就可以隐藏 X 轴网格线, 而只剩下 Y 轴的网格线了吗?

aaOptions.xAxis
            .gridLineColor(AAColor.DarkGray)
            .gridLineWidth(0)

aaOptions.yAxis
            .gridLineColor(AAColor.DarkGray)
            .gridLineWidth(1)

我试过了,就这段代码,设置了之后Y坐标轴没了,回到初始的那个样子了

如果你不是想设置网格线, 而是想设置 Y 轴轴线的话, 参考 AAYAxis 的属性:

    public Number lineWidth; //坐标轴轴线宽度
    public String lineColor; //坐标轴轴线线颜色

在线 API 文档:

Y 轴的坐标轴轴线, 这两个属性你设置了吗?

哦,可以了,感谢大佬,为了这条线我改了两天了,总算弄好了